#[Class]
class TheThing(object):
def __init__(self):
self.number = 0
def some_function(self):
print "I got called."
def add_me_up(self, more):
self.number += more
return self.number
a = TheThing()
b = TheThing()
a.some_function()
b.some_function()
print a.add_me_up(20)
print a.add_me_up(20)
print b.add_me_up(30)
print b.add_me_up(30)
print a.number
print b.number
#Your class should use "camel case" like SuperGoldFactory rather than super_gold_factory.
#Your other functions should use "underscore format" so write my_awesome_hair and not myawesomehair or MyAwesomeHair.
#[getattr()]
#Python’s getattr function is used to fetch an attribute from an object, using a string object instead of an identifier to identify the attribute.
func = getattr(obj, "method", None)
if callable(func):
func(args)
Class getattr()
最新推荐文章于 2022-01-19 16:12:58 发布