__repr__ policy problem: should module be prefixed to output?
scarblac at pino.selwerd.nl
Fri Dec 15 16:57:20 EST 2000
Alex Martelli <aleaxit at yahoo.com> wrote in comp.lang.python:
> "Per Kraulis" <per at sbc.su.se> wrote in message
> news:3A3A3A6D.2C3B1A91 at sbc.su.se...
> > However, I have realized that there is a policy problem. Should __repr__
> > add the module name as prefix to the output string, or not? Or is there
> > some other solution?
> I have exactly the same problem in gmpy (I do supply a portable
> binary picklable string, but also a repr output that is eval'uable
> to restore something 'close to' the original).
Personally I think that this problem isn't that important. Pick one,
be consistent, and it'll be ok. If you start thinking about this sort of
thing a lot, nothing will get done because there are important choices
I went with the module name in __repr__, because of the tiny chance that
I have two classes with the same name in different modules and I want to
be able to tell them apart in the interpreter. But then, without the
module name, the strings are shorter. It doesn't matter much.
More information about the Python-list