首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何将命令行参数传递给ipython

如何将命令行参数传递给ipython
EN

Stack Overflow用户
提问于 2014-03-25 18:33:52
回答 1查看 24.3K关注 0票数 31

在使用ipython时,有没有办法通过命令行将参数传递给我的python脚本?理想情况下,我希望将我的脚本称为:

代码语言:javascript
复制
ipython -i script.py --argument blah

我希望能够在我的sys.argv中列出--argumentblah

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-03-25 18:46:56

您可以在此之前使用一个-- more选项:

代码语言:javascript
复制
ipython  script.py -- --argument blah

Ipython的帮助

代码语言:javascript
复制
ipython [subcommand] [options] [-c cmd | -m mod | file] [--] [arg] ...

If invoked with no options, it executes the file and exits, passing the
remaining arguments to the script, just as if you had specified the same
command with python. You may need to specify `--` before args to be passed
to the script, to prevent IPython from attempting to parse them. If you
specify the option `-i` before the filename, it will enter an interactive
IPython session after running the script, rather than exiting.

演示:

代码语言:javascript
复制
$ cat script.py 
import sys
print(sys.argv)

$ ipython  script.py -- --argument blah
['script.py', '--argument', 'blah']

$ ipython  script.py -- arg1 arg2
['script.py', 'arg1', 'arg2']
票数 59
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22631845

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档