example-code-2e/19-dyn-attr-prop/pseudo_construction.py
2015-04-17 21:29:30 -03:00

11 lines
330 B
Python

# pseudo-code for object construction
def object_maker(the_class, some_arg):
new_object = the_class.__new__(some_arg)
if isinstance(new_object, the_class):
the_class.__init__(new_object, some_arg)
return new_object
# the following statements are roughly equivalent
x = Foo('bar')
x = object_maker(Foo, 'bar')