__repr__ policy problem: should module be prefixed to output?
Per Kraulis
per at sbc.su.se
Fri Dec 15 10:36:13 EST 2000
Having just released a Python extension module crng
(http://www.sbc.su.se/~per/crng/), I have received some constructive
criticism, one issue being save/restore functionality. My plan is to
define a __repr__ for each type in the module.
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?
Alternative 1:
>>> from crng import *
>>> r=ParkMiller()
>>> repr(r)
crng.ParkMiller(seed=314159265)
Alternative 2:
>>> from crng import *
>>> r=ParkMiller()
>>> repr(r)
ParkMiller(seed=314159265)
The problem is that Alt 1 is appropriate in the context of "import
crng", while Alt 2 is better when having done "from crng import *".
A suggestion is that there should be a settable module variable that
controls this. Feels like a kludge to me...
Any ideas which way to go?
--
Per J. Kraulis, Ph.D. per at sbc.su.se
Stockholm Bioinformatics Center (SBC) http://www.sbc.su.se/~per
Dept. Biochemistry, Stockholm University phone +46 (0)8 - 674 78 17
SE-106 91 Stockholm, SWEDEN fax +46 (0)8 - 15 80 57
More information about the Python-list
mailing list