user2112862 user2112862 - 3 months ago 17
Python Question

Create class instance with string input (python)

I want to create class instances and name them with user input strings. Something like this, that actually works. Any ideas?

class Account:
balance=0

input("What's your name?") = Account()


If the user were to type Scott, I would like to be able to call attributes using Scott.balance etc.

GWW GWW
Answer

You are probably better off storing them in a dictionary. Creating variables in the global / local space with user input is a recipe for trouble.

accounts = {}
account[x] = Account()