Có thể có một tập lệnh như sau trong python không?Làm thế nào để tạm dừng và chờ nhập lệnh trong một tập lệnh 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
Về cơ bản, tập lệnh cho phép điều khiển thông dịch dòng lệnh python tạm thời và tiếp tục sau khi người dùng hoàn thành phần đó.
Edit: Những gì tôi đưa ra (lấy cảm hứng từ câu trả lời) là một cái gì đó như sau:
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.'
Câu hỏi này yêu cầu * REPL * ([Read-Eval-Print-Loop] (https://en.wikipedia.org/wiki/Read%E2%80%93eval%E2%80%93print_loop)) . Có một số gợi ý về [một câu hỏi tương tự] (http://stackoverflow.com/questions/1395913/how-to-drop-into-repl-read-eval-print-loop-from-python-code), bao gồm ' code.InteractiveInterpreter() 'và' pdb'. – Possum