[Tutor] Calling instance method in IDLE magically calls __len__?
Steven D'Aprano
steve at pearwood.info
Fri Sep 18 10:03:10 CEST 2015
Hi Dino,
On Fri, Sep 18, 2015 at 09:10:00AM +0200, Dino Bektešević wrote:
> Hello,
>
> For full disclosure, I'm using Python2.7 on Ubuntu 14.04. MWE bellow and at
> https://bpaste.net/show/3d38c96ec938 (until 2015-09-25 06:29:54, in the
> case spaces get messed up).
>
> class Errors:
> def __init__(self):
> pass
> def toFile(self):
> pass
> def __len__(self):
> print "len is called"
> return 0
>
> Which is just fine if I call it over terminal, however calling it in IDLE:
>
> >>> e = Errors()
> >>> len(e)
> len is called
> 0
>
> as expected, but when try to call the method toFile, "len is called" gets
> printed as soon as I put parenthesis "(" behind the toFile.
>
> >>> len is called
> e.toFile(
I'm afraid I cannot replicate that behaviour. Also the output seems
strange -- the "len is called" is printed on the same line as the
prompt, and e.toFile( afterwards.
If you quit idle and restart it, do you get the same behaviour? What's
the exact version of Python?
import sys
print sys.version
--
Steve
More information about the Tutor
mailing list