如何在PyCharm控制台中以我之后可以在命令行中输入的方式运行当前编辑的文件?

时间:2022-05-09 01:06:24

I want this so I can retain the command line history after repeated runs, and to paste lines from the console into tests etc. Exactly like in IDLE.

我希望这样,所以我可以在重复运行后保留命令行历史记录,并将控制台中的行粘贴到测试中等。正好像IDLE一样。

[I realize this question is basically a duplicate of Running a module from the pycharm console. But the question there is not answered satisfyingly (for me), and my lack of reputation does not let me comment there, since I just signed up.]

[我意识到这个问题基本上是从pycharm控制台运行模块的重复。但是那个问题没有得到令人满意的回答(对我来说),而且由于我刚刚注册,我的声誉不足让我在那里发表评论。

3 个解决方案

#1


14  

Select the code fragment or the entire file, then use Execute Selection in Console from the context menu.

选择代码片段或整个文件,然后从上下文菜单中使用Console中的Execute Selection。

#2


15  

Shift+Alt+Ewould execute the selected code.

Shift + Alt + Ewould将执行所选代码。

#3


7  

For anyone still having this problem: Go to the Run/Debug menu, choose Edit Configuration, check the box 'Show command line' this will enable you to enter parameters in the console at the >>> prompt and test your function.

对于仍然遇到此问题的任何人:转到“运行/调试”菜单,选择“编辑配置”,选中“显示命令行”框,这样您就可以在>>>提示符下在控制台中输入参数并测试您的功能。

Edit: To make this change apply to all your .py files (as this check box only applies to the current file you're working on) go to: Edit configuration, in the pop up you will see a menu tree on the left, select Defaults, then Python, then check the 'Show command line' box, this will make it the default setting whenever you open a .py file, (this feature should really be on by default!)

编辑:要使此更改适用于所有.py文件(因为此复选框仅适用于您正在处理的当前文件)转到:编辑配置,在弹出窗口中您将看到左侧的菜单树,选择默认值,然后选择Python,然后选中'显示命令行'框,这将使它成为默认设置,无论何时打开.py文件,(默认情况下该功能应该是真的!)

#1


14  

Select the code fragment or the entire file, then use Execute Selection in Console from the context menu.

选择代码片段或整个文件,然后从上下文菜单中使用Console中的Execute Selection。

#2


15  

Shift+Alt+Ewould execute the selected code.

Shift + Alt + Ewould将执行所选代码。

#3


7  

For anyone still having this problem: Go to the Run/Debug menu, choose Edit Configuration, check the box 'Show command line' this will enable you to enter parameters in the console at the >>> prompt and test your function.

对于仍然遇到此问题的任何人:转到“运行/调试”菜单,选择“编辑配置”,选中“显示命令行”框,这样您就可以在>>>提示符下在控制台中输入参数并测试您的功能。

Edit: To make this change apply to all your .py files (as this check box only applies to the current file you're working on) go to: Edit configuration, in the pop up you will see a menu tree on the left, select Defaults, then Python, then check the 'Show command line' box, this will make it the default setting whenever you open a .py file, (this feature should really be on by default!)

编辑:要使此更改适用于所有.py文件(因为此复选框仅适用于您正在处理的当前文件)转到:编辑配置,在弹出窗口中您将看到左侧的菜单树,选择默认值,然后选择Python,然后选中'显示命令行'框,这将使它成为默认设置,无论何时打开.py文件,(默认情况下该功能应该是真的!)