Bug? print statement ends with ',' print a new line
Fredrik Lundh
fredrik at pythonware.com
Sun Jun 8 06:34:02 EDT 2003
"Lu" <jxlu at fudan.edu.cn> wrote:
> C:\FAT32\py>type counter.py
> import sys
> import threading
>
> class Counter:
> def __init__(self,count=0):
> self.count=count
> def start(self):
> if self.count>0:
> print self.count,'.',
> self.count-=1
> t=threading.Timer(1,self.start)
> t.start()
> elif self.count==0:
> print self.count
>
> counter=Counter(int(sys.argv[1]))
> counter.start()
>
> C:\FAT32\py>counter.py 5
> 5 .
> 4 . 3 . 2 . 1 . 0
if the last print statement in a program doesn't generate a newline,
the interpreter adds a newline when the main thread exits.
in your case, the main thread exits long before the next thread gets
around to print something:
5 . [main program ends here]
4 . 3 . 2 . 1 . 0 [last thread ends here]
to see for yourself, add a print statement or a long sleep to the end
of the main program.
</F>
More information about the Python-list
mailing list