user2112862 user2112862 - 1 year ago 168
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.

Answer Source

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()
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download