I haven’t really used classes outside of tutorials so I’m not too familiar with how to use them in a practical sense.
Typically when creating an instance of a class you would assign it to a variable directly in the script:
var_1 = Class(attr_1, attr_2) var_2 = Class(attr_1, attr_2)
But how would you go about creating an arbitrary number of instances based on user input? There is no variable to begin with so it would need to be created.
I’ve seen some questions about it but no real answers I can relate to. Is this just not done? Is another data structure like a dictionary or database used instead? Or is this where shelving/pickling comes in?
submitted by /u/KevinBrokeBothArms
[link] [comments]
r/learnpython I haven’t really used classes outside of tutorials so I’m not too familiar with how to use them in a practical sense. Typically when creating an instance of a class you would assign it to a variable directly in the script: var_1 = Class(attr_1, attr_2) var_2 = Class(attr_1, attr_2) But how would you go about creating an arbitrary number of instances based on user input? There is no variable to begin with so it would need to be created. I’ve seen some questions about it but no real answers I can relate to. Is this just not done? Is another data structure like a dictionary or database used instead? Or is this where shelving/pickling comes in? submitted by /u/KevinBrokeBothArms [link] [comments]
I haven’t really used classes outside of tutorials so I’m not too familiar with how to use them in a practical sense.
Typically when creating an instance of a class you would assign it to a variable directly in the script:
var_1 = Class(attr_1, attr_2) var_2 = Class(attr_1, attr_2)
But how would you go about creating an arbitrary number of instances based on user input? There is no variable to begin with so it would need to be created.
I’ve seen some questions about it but no real answers I can relate to. Is this just not done? Is another data structure like a dictionary or database used instead? Or is this where shelving/pickling comes in?
submitted by /u/KevinBrokeBothArms
[link] [comments]