简体   繁体   English

如何在Enthought Canopy Editor中为脚本提供命令行参数?

[英]How can I supply command line arguments to a script in Enthought Canopy Editor?

I am using the new Enthought Canopy code editor on OSX (64-bit). 我正在OSX(64位)上使用新的Enthought Canopy代码编辑器。 To test a script, I need to provide a command-line argument like: 要测试脚本,我需要提供一个命令行参数,例如:

import sys
config_file = sys.argv[1]

However, I can't seem to find a way to provide a command line argument to the script. 但是,我似乎找不到找到向脚本提供命令行参数的方法。 I tried using a macro as: 我尝试将宏用作:

def run():
    code_task = get_active_task()
    code_task.run_current_file('config_filename')

...but I get an error that run_current_file only takes one argument (presumably self ). ...但是我收到一个错误,说run_current_file只接受一个参数(大概是self )。

Passing command line argument is not supported currently, but something that we plan to add. 当前不支持传递命令行参数,但我们计划添加该参数。

As a work around, you could run the script normally, first, when it would fail, and then get the previous command from IPython history, and manually add in the args required. 解决方法是,可以正常运行脚本,首先在脚本失败时运行,然后从IPython历史记录中获取上一个命令,然后手动添加所需的args。

Alternatively, you can set sys.argv to the args that you want to pass to your script, before running it. 或者,可以在运行脚本之前将sys.argv设置为要传递给脚本的args。 This seems sort of hackish to me. 对我来说,这似乎有点不足。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM