Can print() be reloaded for a user defined class?
rt8396 at gmail.com
Sun Sep 20 17:49:51 CEST 2009
On Sep 20, 10:16 am, Peng Yu <pengyu... at gmail.com> wrote:
> I am more familiar with C++ than python. So I need to connect python
> concept to C++ concept so that I can understand it better.
> name1 and name are all references (in the C++ sense), right?
> __repr__ and __str__ are references (in the C++ sense) to functions
> and both of them could refer to the same function or two different
> ones, right?
Don't ever try and map C++ to Python on a 1:1 basis or you will get
quite confused. Try this thought experiment, and remember, the Python
shell is your best friend now!
>>> a = 1
>>> b = 1
Help on built-in function id in module __builtin__:
id(object) -> integer
Return the identity of an object. This is guaranteed to be unique
simultaneously existing objects. (Hint: it's the object's memory
NOW you can apply that logic 1:1 to your python problem ;-)
More information about the Python-list