Can print() be reloaded for a user defined class?
davea at ieee.org
Sun Sep 20 16:19:39 CEST 2009
Peng Yu wrote:
>> you might use:
> Is __repr__ =_str__ copy by reference or by value? If I change
> __str__ later on, will __repr__ be changed automatically?
Reference or value? Neither one. This assignment is no different than
any other attribute assignment in Python. Technically, it binds the
name __repr__ to the function object already bound by __str__. You now
have a second name pointing to the same object. Rebinding one of those
names to yet another different object won't affect the other name.
name1 = "this is a test"
name2 = name1
name1 = "another string" #this has no effect on name2
print name1, name2
More information about the Python-list