相关疑难解决方法(0)

为什么在循环中使用睡眠时不能暂停Python中的打印?

这段代码:

import time
for i in range(10):
    print(i)
    time.sleep(.5)
Run Code Online (Sandbox Code Playgroud)

使我的电脑挂起5秒钟,然后打印0-9,而不是每半秒打印一个数字.难道我做错了什么?

python python-3.x

9
推荐指数
1
解决办法
3299
查看次数

为什么time()低于0.25会在Python中跳过动画?

此代码按预期工作.输出:

Loading 
Loading.
Loading..
Loading...
Run Code Online (Sandbox Code Playgroud)

码:

done = False
count = 0

while not done:
    print '{0}\r'.format("Loading"),
    time.sleep(0.25)
    print '{0}\r'.format("Loading."),
    time.sleep(0.25)
    print '{0}\r'.format("Loading.."),
    time.sleep(0.25)
    print '{0}\r'.format("Loading..."),
    time.sleep(0.25)
    count += 1
    if count == 5:
        done = True
Run Code Online (Sandbox Code Playgroud)

而这段代码没有.输出:

Loading.
Loading...
Run Code Online (Sandbox Code Playgroud)

码:

done = False
count = 0

while not done:
    print '{0}\r'.format("Loading"),
    time.sleep(0.125)
    print '{0}\r'.format("Loading."),
    time.sleep(0.125)
    print '{0}\r'.format("Loading.."),
    time.sleep(0.125)
    print '{0}\r'.format("Loading..."),
    time.sleep(0.125)
    count += 1
    if count == 5:
        done = True
Run Code Online (Sandbox Code Playgroud)

为什么时间函数似乎跳过每一个print语句,如果它低于0.25?

python time stdout python-2.7

5
推荐指数
1
解决办法
135
查看次数

标签 统计

python ×2

python-2.7 ×1

python-3.x ×1

stdout ×1

time ×1