Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tell Python to wait/pause a 'for' loop

Tags:

python

loops

I have a Python program that navigates me to a website with a function that I have defined as nav(a, b), and on this site I will be downloading some pyfits data for use on another script. This site has a different pyfits file for every set of (a,b) in a catalog I have.

I was wondering if I could iterate through this catalog using a for loop, and each time the nav(a, b) function is used, tell python to pause while I download the file, then resume again when I tell it to. I've done something like this in IDL before, but don’t know how with Python.

Otherwise I guess I'm stuck running the program 200 times, replacing the (a, b) values each time, which will take for ever.

like image 292
user3715675 Avatar asked Jun 25 '14 13:06

user3715675


People also ask

How do you wait 10 seconds in Python?

If you've got a Python program and you want to make it wait, you can use a simple function like this one: time. sleep(x) where x is the number of seconds that you want your program to wait.

How do you make Python wait before continuing?

There are two ways to do this: Use time.sleep() as before. Use Event.wait() from the threading module.

How do I add a pause in Python?

Python sleep() function will pause Python code or delay the execution of program for the number of seconds given as input to sleep(). The sleep() function is part of the Python time module. You can make use of Python sleep function when you want to temporarily halt the execution of your code.


1 Answers

If you want to wait for a manual signal to continue, wait for the user to press Enter:

Python 2:

raw_input("Press Enter to continue...")

Python 3:

input("Press Enter to continue...")

If you can download the file in the python code, do that instead of doing the manual task for each of the files.

like image 170
Mattias Backman Avatar answered Oct 17 '22 05:10

Mattias Backman