Reputation: 65
I'm wondering how I can restart a script without just calling the function itself. You can see the example below. After "two" is printed I want the script to restart itself without just calling one().
import time
zero = 0
def one():
global zero
for i in range(50):
time.sleep(0.5)
zero += 1
print(zero)
if zero == 10:
two()
def two():
print("two")
#Restart the script
one()
Upvotes: 0
Views: 103
Reputation: 2061
You can try with a while
loop,
import time
zero = 10
i = 0
while i <= zero:
time.sleep(0.5)
zero += 1
print(zero)
print("two")
Upvotes: 0
Reputation: 23624
You want to do some condition forever, so the most practical way is to use a while loop with a condition that is always true.
while True:
one()
You probably also want to return from function one
after calling two
if zero == 10:
two()
return
Upvotes: 3