[Tutor] time.sleep
Mallett, Roger
rmallett@rational.com
Wed, 22 Nov 2000 10:47:21 -0800
Concerning the time.sleep function I have a couple of questions.
In TEST 1 (below), I placed a sleep between two prints. However, when the
code was executed, the sleep occurred before the first print displayed to
the screen.
Question: Why did the sleep occur before "line 1" was printed to
the screen?
In TEST 2 (below), I attempted to pass in a value to sleep which resulted in
an error. I also tried passing in a long, same results.
Question: Why the error? How should I pass a value into sleep?
Any assistance is greatly appreciated.
Thank you,
Roger Mallett
TEST 1
>>> def test1():
... print 'line 1'
... time.sleep(2)
... print 'line 2'
...
>>> test1()
line 1
line 2
TEST 2
>>> def test2(time):
... print 'line 1'
... time.sleep(time)
... print 'line 2'
...
>>> test2(1)
line 1
Traceback (innermost last):
File "<interactive input>", line 1, in ?
File "<interactive input>", line 3, in test2
AttributeError: 'int' object has no attribute 'sleep'
>>>