[python3]

Kevin Adams incensedprey at gmail.com
Fri Mar 26 10:05:52 EDT 2010


On Mar 19, 3:02 pm, Terry Reedy <tjre... at udel.edu> wrote:
> On 3/19/2010 2:17 PM, Steve Holden wrote:
>
>
>
> > Kevin Adams wrote:
> >> Greetings!
>
> >> 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
> >> "end=''".
>
> >> Thanks in advance for any help.
>
> > Try the following changes:
>
> >> ---code---
>
> >> 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
>
> > import sys
>
> >> if __name__ == "__main__":
>
> >>      me = TestClass()
> >>      for x in me:
> >>          print(x,end='')  #if i remove the 'end='''  it performs as i'd
> >> expect
> >            sys.stdout.flush()
>
> >>          time.sleep(int(2))
>
> > It may just be that the output is being held in buffers until the
> > program terminates. the fluch() methof pushes it straight out.
>
> The IDLE Shell window must get print output back from the pythonw
> process without buffering. When I cut and pasted from IDLE editor to
> standard interpreter window, output was bunched after several seconds.
> OP should have started with short string and minimal delay so output
> would not take a whole minute. Flushing fixed problem in standard
> interpreter. I will have to remember that testing partial line output in
> IDLE does not show how it will act elsewhere.
>
> Kevin: when reporting a problem, be more specific as to what 'does not
> work' means.
>
> Terry Jan Reedy

Terry:  Will definately try to be more informative next time.   Thanks
again.

K



More information about the Python-list mailing list