[Python-ideas] Changing str(someclass) to return only the class name

Arnaud Delobelle arnodel at gmail.com
Sat Oct 22 23:43:31 CEST 2011


On 22 October 2011 22:33, Antoine Pitrou <solipsis at pitrou.net> wrote:
> On Sat, 22 Oct 2011 18:32:25 +1100
> Steven D'Aprano <steve at pearwood.info> wrote:
>> Remember also that print(spam) will use str(spam). If you do this:
>>
>>  >>> print(spam)
>> something
>>
>>
>> what would you expect spam is?
>
> What if:
>
>>>> print(spam)
> 1
>
> It might be the integer 1 or the string "1". You need repr() to tell
> the difference.

Indeed:

>>> print(A)
<class '__main__.A'>
>>> A
"<class '__main__.A'>"

-- 
Arnaud



More information about the Python-ideas mailing list