Skip to content
Advertisement

issue with setting concatenated string variables in __init__ using variables set within __init__ as part of the concatenated string [closed]

I am writing a class called “USR” that holds some information about a user who creates an account on my command line e-commerce store (its a college group project that I’m having to do by myself bc ppl are lazy)

the contents of USR are as follows:

JavaScript

UserCart and OrderHistory are supposed to be strings that when a user is created, grab the current directory, + the Username of the USR instance, + "_UC.csv" or "_OH.csv" respectively.

in my testing function. i am doing the following:

JavaScript

when the code is run in the command line (OS = win10) i get the following error

JavaScript

I’m assuming this is because of the fact that the Username attribute is set in the same function? i don’t really know what to do about this.

Any tips or solutions are welcome, thank you!

I’ve tried setting them to use self.Name aswell, i still get the same attribute error. I’m not sure what else to try to solve the issue at hand.

Advertisement

Answer

JavaScript

You need to put self. in front of these variable names. self.Name = N, etc.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement