python - 如何将 args 传递给 python shell
问题描述
我想sys.argv
在 python shell 中玩弄这些项目。有没有办法传递任意参数,例如:
$ python one two three
它会打开python shell,我可以获得以下信息:
>>> import sys
>>> sys.argv
# ['python', 'one', 'two', three'], or ['one', 'two', 'three']
解决方案
您可以在连字符后传递这些参数,例如:
$ python - one two three
在这种情况下,sys.argv
将产生['-', 'one', 'two', 'three']
推荐阅读
- angular - Angular8 - 从 API 端点获取数据到自动完成
- skipper - 我如何在船长服务器上注册我的本地 jar
- javascript - 从另一个文件导出函数时没有这样的文件或目录
- android - 如何检测用户是否在android中打开了开发者选项
- qt - SDL 和 Qt。从另一个线程渲染时,调整应用程序大小会导致显示冻结
- java - 我的 serverlet 运行没有任何问题,但数据没有插入到数据库中。为什么?
- javascript - 在每个滚动条上移动元素
- excel - Listbox_Click 在选择新条目之前运行命令
- javascript - Sentry:如何在 Redux 中配置 Sentry 以在对 Api 调用失败的情况下报告错误?
- java - 从现有 Cipher 中获取密码模式和填充方案