Author Radu.Dan
Recipients Radu.Dan
Date 2012-10-08.16:58:20
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1349715500.68.0.716080336788.issue16167@psf.upfronthosting.co.za>
In-reply-to
Content
Classes that extend the builtin 'str' cannot be printed as is, and are automatically converted to string.

#!/bin/env python
class newstring(str):
        def __str__(self):
                return self

a = newstring("hello world")
print a

Running this returns:

Traceback (most recent call last):
  File "./test.py", line 7, in <module>
    print a
RuntimeError: print recursion

Given that instances of 'str' are immutable, I see no reason why this should not work.
History
Date User Action Args
2012-10-08 16:58:20Radu.Dansetrecipients: + Radu.Dan
2012-10-08 16:58:20Radu.Dansetmessageid: <1349715500.68.0.716080336788.issue16167@psf.upfronthosting.co.za>
2012-10-08 16:58:20Radu.Danlinkissue16167 messages
2012-10-08 16:58:20Radu.Dancreate