How to pause and wait for command input in a Python script

python

Solution

if you are using Python 2.x: `raw_input()`

Python 3.x: `input()`

Example:

# Do some stuff in script
variable = raw_input('input something!: ')
# Do stuff with variable

Problem

Is it possible to have a script like the following in Python? ``` ... Pause -> Wait for the user to execute some commands in the terminal (e.g. to print the value of a variable, to import a library, or whatever). The script will keep waiting if the user does not input anything. -> Continue execution of the remaining part of the script ``` Essentially the script gives the control to the Python command line interpreter temporarily, and resume after the user somehow finishes that part. What I come up with (inspired by the answer) is something like the following: ``` x = 1 i_cmd = 1 while True: s = raw_input('Input [{0:d}] '.format(i_cmd)) i_cmd += 1 n = len(s) if n > 0 and s.lower() == 'break'[0:n]: break exec(s) print 'x = ', x print 'I am out of the loop.' ```

Original source

Related problems