也许是sleep()函数。 [英] sleep() function, perhaps.

查看:65
本文介绍了也许是sleep()函数。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



大家好,


我希望有一排句号,相隔小,比如说.5秒
$ b彼此间隔$ b。因此,例如,使其具有进度bar的

外观。


[code]

import时间


睡觉(.5)

打印""

睡觉(.5)

print"。"

[结束代码]


但是,它会(以0.5秒的间隔)

打印出来如下。


..

(暂停)

..

(暂停)


我宁愿将这些时间段放在一行上,而不是每次都打印新的
行。


有什么建议吗?


提前谢谢,

~瑞安


Hello Everyone,

I want to have a row of periods, separated by small, say, .5 second
intervals between each other. Thus, for example, making it have the
appearance of a progress "bar".

[code]
import time

sleep(.5)
print "."
sleep(.5)
print "."
[end code]

But, it would (with those .5 second intervals)
print out much like the following.

..
(pause)
..
(pause)

I would rather those periods be on a single line, not printing on a new
line each time.

Any suggestions?

Thank you in advance,
~Ryan

推荐答案

" Ryan Spencer" < JE *** @ earthlink.net> schrieb im Newsbeitrag

新闻:pa **************************** @ earthlink.net。 ..

|

|大家好,

|

|我希望有一排句子,分隔小,比如说.5秒

|彼此之间的间隔。因此,例如,使它具有

|出现进度bar。

|

| [code]

|进口时间

|

|睡觉(.5)

|打印。"

|睡觉(.5)

|打印。"

| [结束代码]

|

|但是,它会(以0.5秒的间隔)

|打印出来如下。


|

| 。

| (暂停)

| 。

| (暂停)

|

|我宁愿那些时期是单行,而不是打印新的


导入时间,sys


而1:

sys.stdout.write(" ;。")

time.sleep(0.5)


你也可以使用:


print" ;。",


(注意尾随的逗号)


但是这会在点之后给你一个额外的空间

HTH,


Vincent Wehren

|有什么建议吗?

|

|提前谢谢,

| ~Ryan

|
"Ryan Spencer" <je***@earthlink.net> schrieb im Newsbeitrag
news:pa****************************@earthlink.net. ..
|
| Hello Everyone,
|
| I want to have a row of periods, separated by small, say, .5 second
| intervals between each other. Thus, for example, making it have the
| appearance of a progress "bar".
|
| [code]
| import time
|
| sleep(.5)
| print "."
| sleep(.5)
| print "."
| [end code]
|
| But, it would (with those .5 second intervals)
| print out much like the following.

|
| .
| (pause)
| .
| (pause)
|
| I would rather those periods be on a single line, not printing on a new
| line each time.

import time,sys

while 1:
sys.stdout.write(".")
time.sleep(0.5)

You could also use:

print ".",

(note the trailing comma)

but that will leave you with an additional space after the dot

HTH,

Vincent Wehren
| Any suggestions?
|
| Thank you in advance,
| ~Ryan
|


On Tue,2003年11月25日05:26:25 GMT,Ryan Spencer< je *** @ earthlink。 net>

写道:
On Tue, 25 Nov 2003 05:26:25 GMT, Ryan Spencer <je***@earthlink.net>
wrote:

大家好,

我想有一排句号,由小,比如说.5秒之间的间隔。因此,例如,使其具有进度bar的外观。

[code]
导入时间

睡眠(。 5)
print""
sleep(.5)
print"。"
[end code]

但是,它会(那些.5秒间隔)
打印出来,如下所示。


(暂停)

(暂停)

我宁愿那些时期在一条线上,而不是每次都在新的
线上打印。

有什么建议吗?

Hello Everyone,

I want to have a row of periods, separated by small, say, .5 second
intervals between each other. Thus, for example, making it have the
appearance of a progress "bar".

[code]
import time

sleep(.5)
print "."
sleep(.5)
print "."
[end code]

But, it would (with those .5 second intervals)
print out much like the following.

.
(pause)
.
(pause)

I would rather those periods be on a single line, not printing on a new
line each time.

Any suggestions?




尝试使用添加的逗号或sys.stdout.write进行打印,如下所示:



Try print with added comma or sys.stdout.write, like so:

进口时间
我的范围(10):
....打印''\ b。'',

.... time.sleep(1.5)

....

...........导入系统
我的范围(10):
import time
for i in range(10): .... print ''\b.'',
.... time.sleep(1.5)
....
........... import sys
for i in range(10):



.... sys.stdout.write(''。'')

.... time.sle ep(0.5)

....

...........

-

Christopher


.... sys.stdout.write(''.'')
.... time.sleep(0.5)
....
...........
--
Christopher


2003年11月25日星期二06:14:20 +0000,Christopher Koppler写道:
On Tue, 25 Nov 2003 06:14:20 +0000, Christopher Koppler wrote:
On星期二,2003年11月25日05:26:25 GMT,Ryan Spencer< je *** @ earthlink.net>
写道:
On Tue, 25 Nov 2003 05:26:25 GMT, Ryan Spencer <je***@earthlink.net>
wrote:

大家好,

我希望有一行句点,相隔小的,比如说.5秒间隔。因此,例如,使其具有进度bar的外观。

[code]
导入时间

睡眠(。 5)
print""
sleep(.5)
print"。"
[end code]

但是,它会(那些.5秒间隔)
打印出来,如下所示。


(暂停)

(暂停)

我宁愿那些时期在一条线上,而不是每次都在新的
线上打印。

有什么建议吗?

Hello Everyone,

I want to have a row of periods, separated by small, say, .5 second
intervals between each other. Thus, for example, making it have the
appearance of a progress "bar".

[code]
import time

sleep(.5)
print "."
sleep(.5)
print "."
[end code]

But, it would (with those .5 second intervals)
print out much like the following.

.
(pause)
.
(pause)

I would rather those periods be on a single line, not printing on a new
line each time.

Any suggestions?



尝试使用添加的逗号或sys.stdout.write进行打印,如下所示:



Try print with added comma or sys.stdout.write, like so:

导入时间
for i in range(10 ):...打印''\b。'',
... time.sleep(1.5)
...
.......... import系列
我在范围内(10):
import time
for i in range(10): ... print ''\b.'',
... time.sleep(1.5)
...
.......... import sys
for i in range(10):


... sys.stdout.write(''。'')
... time.sleep (0.5)
.....
..........


... sys.stdout.write(''.'')
... time.sleep(0.5)
...
..........



Heya'',谢谢,


实际上,这些建议都没有给我想要的结果

我一直在寻找。我使用了for循环,甚至是带有

while循环的那个,并且对于第一个建议它将所有这些打印出来在新的

在一条线上的第二个帖子,但是,这些时期仍然没有暂停

他们之间。也许还有其他不妥之处?


同样,尾随逗号的结果与执行

sys.stdout.write函数完全相同。


您建议的代码是否给您一个结果,例如......


..(暂停)。(暂停)。(暂停)。


我把所有东西都提升到1.5秒的时间间隔来夸大结果,

我恐怕还没有注意到暂停。


我只需要删除终止该行的内容吗?

time.sleep()函数本身是否终止了一行?如果我可以绕过它,它会显示

,它会允许暂停并在一行上保留期限




感谢您的建议,非常感谢。


~Ryan


Heya'', Thanks,

Actually though, None of those suggestions give me the desired result
I was looking for. I used both with the for loops, even the one with the
while loop, and for the first suggested it prints all of them out on new
lines (as opposed to all on the same line as I''d been hoping for) and the
second posts on one full line, yet, the periods still don''t have pauses
between themselves. Perhaps something else is amiss?

As well, the trailing commas gives the exact same result as doing the
sys.stdout.write function.

Is the code that you suggested giving you a result such as...

..(pause).(pause).(pause).

I raised everything up to a 1.5 second interval to exaggerate the results,
and I''m afraid I still don''t notice the pauses.

Perchance I simply need to remove whatever is terminating the line?
Does the time.sleep() function itself terminate a line? It would seem
if I could bypass that, it would allow the pauses and keep the periods
on one line.

Thank you for your advice though, It''s highly appreciated.

~Ryan


这篇关于也许是sleep()函数。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆