Python 如何在 Pycharm 中运行代码

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/42846803/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 22:12:08  来源:igfitidea点击:

How to run code in Pycharm

pythonpycharm

提问by Kyle

If I go to "tools" and select "python console", and enter several lines of code, how do I execute this? If my cursor is at the end of the script, I can just hit enter. But how can I run the code using keyboard shortcuts if the cursor is not at the end? In Spyder this is done using shift+enter, but I can't figure out how to do it here. I've seen places say control+enter, but that doesn't work. Thanks!

如果我转到“工具”并选择“python 控制台”,然后输入几行代码,我该如何执行?如果我的光标在脚本的末尾,我可以直接按回车键。但是,如果光标不在末尾,如何使用键盘快捷键运行代码?在 Spyder 中,这是使用 shift+enter 完成的,但我不知道如何在此处执行此操作。我见过一些地方说控制+输入,但这不起作用。谢谢!

回答by Emmanuel Olujobi

If you use Win 10, 64Bits. Run your codes using Ctrl + Shift + F10or simply right click on the workspace and click Runfrom the options.

如果您使用 Win 10,64 位。使用Ctrl + Shift + F10运行您的代码,或者只需右键单击工作区并从选项中单击运行

回答by pwcahyo

in mac. you can use fn+shift+f10and happy coding with python

在麦克。你可以使用fn+shift+f10并用 python 快乐编码

回答by user10356062

Right click on project name / select New / select Python File

右键单击项目名称/选择新建/选择 Python 文件

Pycharm needs to know you're running a Python file before option to run is available

在运行选项可用之前,Pycharm 需要知道您正在运行 Python 文件

回答by user2762934

From Jetbrains' official documentation: PyCharm suggests several ways to run a script opened in the editor:

来自 Jetbrains 的官方文档:PyCharm 建议了几种运行在编辑器中打开的脚本的方法:

  • First, you can use the keyboard shortcut ??R

  • Second, you can use the context menu command (here Run Solver), invoked by right-clicking the editor background

  • Use the main menu Run | Run, Run | Run 'Solver'
  • Finally, it is possible to run a script from the main toolbar, using the temporary run/debug configuration Solver
  • 首先,您可以使用键盘快捷键 ??R

  • 其次,您可以使用上下文菜单命令(此处为 Run Solver),通过右键单击编辑器背景调用

  • 使用主菜单运行 | 跑,跑 | 运行“求解器”
  • 最后,可以使用临时运行/调试配置 Solver 从主工具栏运行脚本