[英]Python - Running just a single line of code, and not the rest of the Multiple lines in the Script
In - Python, inside the the IDLE, in the File Editor Window, 在-Python中,在IDLE中,在文件编辑器窗口中,
How do you run just a selected single line of code in the script, without having the rest of the lines of the program being runned ? 如何在脚本中仅运行选定的单行代码,而不运行程序的其余行?
You'll have to run your line of code form command line: 您必须运行代码行命令行:
With the -c (command) argument (assuming your file is named foo.py): 使用-c(命令)参数(假设您的文件名为foo.py):
$ python -c 'import foo; print foo.hello()'
You can select and copy a single statement in an Idle editor (or anywhere else, for that matter), switch to the Idle Shell, and paste on the line with the >>> prompt as the bottom. 您可以在Idle编辑器中(或其他任何地方)选择并复制一条语句,切换到Idle Shell,然后将>>>提示作为底部粘贴在该行上。 (You can hit to get a clean prompt.) Then hit return just as it you had entered into the shell directly. (您可以按一下以得到一个干净的提示。)然后按回车键,就像直接进入外壳一样。 This works for multiline statements. 这适用于多行语句。 Being able to do this with a menu selection, hotkey, or right-click selection is on my todo list, as you are not the first to ask about this. 可以通过菜单选择,热键或右键选择来执行此操作,这在我的待办事项列表中,因为您不是第一个询问此问题的人。
Basically, what we call "debugger" should be fulfilled your requirement. 基本上,我们所谓的“调试器”应满足您的要求。 Many IDEs are provided "debugger tools" including IDLE
. 提供了许多IDE“调试器工具”,包括IDLE
。 To use a debugger tool you can just simply 要使用调试器工具,您只需
step
to go to the next breakpoint. 单击/键入step
转到下一个断点。 This is just a roughly procedure that should be fit to your requirement. 这只是一个粗略的过程,应该适合您的要求。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.