简体   繁体   English

从命令行运行python脚本,然后进入交互模式

[英]run python script from command line and then enter interactive mode

Is there a way to run a python module from command line ( -m option, which imports and runs a module ), and then enter the interactive mode? 有没有办法从命令行运行python模块(-m选项,导入并运行模块),然后进入交互模式?

I need something similar to "cmd /k command". 我需要类似“cmd / k命令”的东西。

I tested the -i option, but it didn't work; 我测试了-i选项,但它没有用; I'm not sure but it seems just redirects in_stream from input. 我不确定,但似乎只是从输入重定向in_stream。

You need to put the -i before the -m . 你需要在-m之前放置-i

The -m option is an interface option; -m选项是一个接口选项; it terminates the option list and all subsequent arguments will end up in sys.argv for the module's main function. 它终止了选项列表,所有后续参数将以sys.argv结尾,用于模块的main函数。 ( link to doc ) 链接到doc

或者进入交互模式并运行你的python文件:

import <filename>

You can use bpython in the following way: 您可以通过以下方式使用bpython

bpython -i <filename>

which will load the module and get into interactive mode 这将加载模块并进入交互模式

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

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