在IDLE中运行python脚本时,是否可以传递命令行参数(args)? [英] When running a python script in IDLE, is there a way to pass in command line arguments (args)?
本文介绍了在IDLE中运行python脚本时,是否可以传递命令行参数(args)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在测试一些解析命令行输入的python代码。有没有办法通过IDLE传递此输入?目前,我正在保存IDLE编辑器并从命令提示符运行。
I'm testing some python code that parses command line input. Is there a way to pass this input in through IDLE? Currently I'm saving in the IDLE editor and running from a command prompt.
我正在运行Windows。
I'm running Windows.
推荐答案
IDLE似乎没有提供通过GUI进行此操作的方法,但是您可以执行以下操作:
It doesn't seem like IDLE provides a way to do this through the GUI, but you could do something like:
idle.py -r scriptname.py arg1 arg2 arg3
您还可以手动设置 sys.argv
,例如:
You can also set sys.argv
manually, like:
try:
__file__
except:
sys.argv = [sys.argv[0], 'argument1', 'argument2', 'argument2']
(信用 http://wayneandlayne.com/2009/04/14/using-command-line-arguments-in-python-in-idle/ )
这篇关于在IDLE中运行python脚本时,是否可以传递命令行参数(args)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文