無限ループで経過した秒数をどのように測定する必要がありますか?私はVpythonを使用しており、ループ内でいくつかの要素などの位置を変更しています。X秒ごとにライト(球)の色を変更する必要があり、すべて無限ループで発生します。
while True:
#some stuff
'here i have to count those seconds'
#some other stuff
無限ループで経過した秒数をどのように測定する必要がありますか?私はVpythonを使用しており、ループ内でいくつかの要素などの位置を変更しています。X秒ごとにライト(球)の色を変更する必要があり、すべて無限ループで発生します。
while True:
#some stuff
'here i have to count those seconds'
#some other stuff
time.time()
を呼び出して差をとることで、経過時間を判断できます。
X秒ごとにライト(球)の色を変更する必要があります
最後に色を変更したとしましょうT
。time.time()
ループ内で呼び出しを続け、time.time() - T
を超えたら色を再度変更しX
ます。
おそらくtimeit.default_timer()
、現在時刻を把握し、差を計算するために を使用する必要があります。
例えば:
from timeit import default_timer
clock_start = default_timer()
#... do something here
clock_end = default_timer()
print "This took %s seconds" %( clock_end - clock_start )