![](https://secure.gravatar.com/avatar/31532f7e57248619b254d175b69936b4.jpg?s=120&d=mm&r=g)
This came up on an internal discussion, I thought it was fun, especially given that we all behave differently: Paste this into the REPL: class PS1(object): def __init__(self): self.count = 0 def __str__(self): self.count += 1 return "%d >>>" % self.count import sys sys.ps1 = PS1() CPython - calls __str__ Jython - calls __repr__ IronPython - ignores ps1 PyPy - unsupported operand type for unary buffer: 'PS1' (note I don't necessarily have the latest versions for everyone)
![](https://secure.gravatar.com/avatar/cdc3cafa377f0e0e93fc69636021ef65.jpg?s=120&d=mm&r=g)
On 01/09/11 05:28, Dino Viehland wrote:
This came up on an internal discussion, I thought it was fun, especially given that we all behave differently:
Paste this into the REPL: [cut]
it seems to work fine with pypy 1.6. Note that str() is called twice for each line, so we get 1, 3, 5, 7..., but this happens only on cpython.
class PS1(object): .... def __init__(self): .... self.count = 0 .... def __str__(self): .... self.count += 1 .... return "%d >>>" % self.count .... import sys sys.ps1 = PS1() 1 >>> 3 >>> 5 >>> 7 >>> 9 >>>
ciao, Anto
![](https://secure.gravatar.com/avatar/5b37e6b4ac97453e4ba9dba37954cf79.jpg?s=120&d=mm&r=g)
Hi, On Thu, Sep 1, 2011 at 9:58 AM, Antonio Cuni <anto.cuni@gmail.com> wrote:
it seems to work fine with pypy 1.6. Note that str() is called twice for each line, so we get 1, 3, 5, 7..., but this happens only on cpython.
...but this happens only on PyPy, you mean. It works as expected on CPython 2.7. Is it a bug? :-) A bientôt, Armin.
![](https://secure.gravatar.com/avatar/cdc3cafa377f0e0e93fc69636021ef65.jpg?s=120&d=mm&r=g)
On 01/09/11 10:57, Armin Rigo wrote:
Hi,
On Thu, Sep 1, 2011 at 9:58 AM, Antonio Cuni<anto.cuni@gmail.com> wrote:
it seems to work fine with pypy 1.6. Note that str() is called twice for each line, so we get 1, 3, 5, 7..., but this happens only on cpython.
...but this happens only on PyPy, you mean. It works as expected on CPython 2.7. Is it a bug? :-)
no, I wanted to write "it happens *also* on cpython". Note that I use pyrepl both on pypy and cpython, so it's probably pyrepl's "fault" (assuming it's a fault, I'm happy to ignore it :-))
participants (3)
-
Antonio Cuni
-
Armin Rigo
-
Dino Viehland