steve at holdenweb.com
Fri Mar 19 19:17:31 CET 2010
Kevin Adams wrote:
> Please forgive me if im posting this to the wrong group.
> I'm new to Python, learning Python3 from the O'rielly "Learning
> Python" book. Reading
> about operator overloading, specifically __getitem__. I put together
> a small bit of code to
> do some experimenting and threw in a timer so i can see it do its
> thing. For some reason
> the time.sleep(x) function doesnt work when my print function includes
> Thanks in advance for any help.
Try the following changes:
> class TestClass():
> def __init__(self):
> self.data = "I was far from home and the spell of the eastern
> sea was upon me."
> def __getitem__(self,i):
> return self.data[i]
> import time
> if __name__ == "__main__":
> me = TestClass()
> for x in me:
> print(x,end='') #if i remove the 'end=''' it performs as i'd
It may just be that the output is being held in buffers until the
program terminates. the fluch() methof pushes it straight out.
Steve Holden +1 571 484 6266 +1 800 494 3119
See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/
Holden Web LLC http://www.holdenweb.com/
UPCOMING EVENTS: http://holdenweb.eventbrite.com/
More information about the Python-list