Codes are as follows:
class Test: a = 1 def __init__(self): self.b=2
When I make an instance of Test , I can access its instance variable b , like this (using the string "b"):
test = Test() a_string = "b" print test.__dict__[a_string]
But this does not work for a , since self.__dict__ does not contain a key named a . Then how can I access a if I only have string a ?
Thanks!
variables python class
Hanfei sun
source share