In Python, how do I check if an instance of my class exists? -
i'm making program asks user login, , i'm wondering how can make checks if instance of username class exists. oh , please excuse sloppy , disorganized coding, i'm not @ it.
quit_login = 1 class usernames: def __init__(self, password): self.password = password testlogin = usernames("foo") def login_e(): = raw_input("please enter username: ") new_pass = "" if isinstance(a, usernames): = usernames(new_pass) print usernames else: login_pass = raw_input("what password?\n") if login_pass == a.password: print "hello", else: print "incorrect password" while quit_login != 0: login_e()
the missing piece collection hold usernames
instances. particular scenario, want dictionary.
>>> mydict = {} >>> mydict['foo'] = 5 >>> 'foo' in mydict true >>> mydict['foo'] 5 >>> mydict.get('bar', 'nope') 'nope' >>>
Comments
Post a Comment