Created on 2007-07-11 01:48 by christian.heimes, last changed 2008-01-06 22:29 by admin.
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2008-01-06 22:29:46 | admin | set | keywords:
- py3k versions: + Python 3.0 |
| 2007-07-11 01:48:05 | christian.heimes | create | |
Created on 2007-07-11 01:48 by christian.heimes, last changed 2008-01-06 22:29 by admin.
| Messages (1) | |||
|---|---|---|---|
| msg32472 - (view) | Author: Christian Heimes (christian.heimes) | Date: 2007-07-11 01:48 | |
In the py3k-struni branch the str() constructor doesn't use __str__ when the argument is an instance of a subclass of str. A user defined string can't change __str__().
It works in Python 2.5 and in the p3yk branch.
Python 3.0x (py3k-struni:56245, Jul 10 2007, 23:34:56)
[GCC 4.1.2 (Ubuntu 4.1.2-0ubuntu4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> class Mystr(str):
... def __str__(self): return 'v'
...
>>> s = Mystr('x')
>>> s
'x'
>>> str(s)
'x' # <- SHOULD RETURN 'v'
Python 2.5.1 (r251:54863, May 2 2007, 16:56:35)
[GCC 4.1.2 (Ubuntu 4.1.2-0ubuntu4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> class Mystr(str):
... def __str__(self): return 'v'
...
>>> s = Mystr('x')
>>> s
'x'
>>> str(s)
'v'
Python 3.0x (p3yk:56180, Jul 6 2007, 23:35:08)
[GCC 4.1.2 (Ubuntu 4.1.2-0ubuntu4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> class Mystr(str):
... def __str__(self): return 'v'
...
>>> s = Mystr('x')
>>> s
'x'
>>> str(s)
'v'
|
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2008-01-06 22:29:46 | admin | set | keywords:
- py3k versions: + Python 3.0 |
| 2007-07-11 01:48:05 | christian.heimes | create | |