[Python-Dev] Replacement for print in Python 3.0

skip@pobox.com skip at pobox.com
Tue Sep 6 04:40:10 CEST 2005


 Neil> In interactive mode, you are normally interested in the values of
 Neil> things, not their formatting so it does the right thing. 
 >>> class Dumb:
 ... def __init__(self, val):
 ... self.val = val
 ... def __str__(self):
 ... return "<Dumb val=%s>" % self.val
 ... 
 >>> d = Dumb(5)
 >>> d
 <__main__.Dumb instance at 0x11042d8>
 >>> print d
 <Dumb val=5>
It's just repr() vs. str(), but the difference can be significant in many
circumstances.
Skip


More information about the Python-Dev mailing list

AltStyle によって変換されたページ (->オリジナル) /