user2112862 user2112862 - 8 months ago 72
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:

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.


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()