Message172396
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. |
|
Date |
User |
Action |
Args |
2012-10-08 16:58:20 | Radu.Dan | set | recipients:
+ Radu.Dan |
2012-10-08 16:58:20 | Radu.Dan | set | messageid: <1349715500.68.0.716080336788.issue16167@psf.upfronthosting.co.za> |
2012-10-08 16:58:20 | Radu.Dan | link | issue16167 messages |
2012-10-08 16:58:20 | Radu.Dan | create | |
|