[pypy-dev] Here's a fun one...

Antonio Cuni anto.cuni at gmail.com
Thu Sep 1 09:58:14 CEST 2011


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


More information about the pypy-dev mailing list