英文:
How apply optimization flag for run but not debug for default configurations?
问题
我想要修改Pycharm中默认的运行(非调试)行为,以包括-O
标志,如此答案中所示。
在此答案中关于创建运行配置的信息很有帮助,但我有许多带有if __name__ == "__main__"
块的文件,我需要在本地运行它们,并且我希望Pycharm在“运行”期间自动使用-O
选项执行它们。调试行为应保持不变,不应设置-O
标志。
英文:
I would like to modify the default run (not debug) behavior in Pycharm to include the -O
flag, as indicated in this answer.
The information in this answer on creating a run configuration is helpful, but I have many files with if __name__ == "__main__"
blocks that I need to run locally, and I would like Pycharm to automatically execute them with the -O
option during a "run". The debug behavior should remain unchanged and the -O
flag shouldn't be set.
答案1
得分: 1
-O 用于运行而非调试
你不能通过配置完成这个操作,但可以使用 Pycharm 的外部工具功能。
你可以配置一个外部工具配置(设置 > 工具 > "外部工具" > 添加),如下所示:
然后,你可以在键盘映射中为运行此配置分配一个快捷键,这将在当前文件上使用优化标志运行 Python。
-O 用于默认配置(运行/调试)
使用 运行/调试配置 > 编辑配置模板
你不能基于文件内容选择配置(或者不容易实现),也不能更改运行或调试时的选项,但可以更改用于配置的默认模板,以在解释器选项中包含 -O
标志。
英文:
-O for run but not Debug
You can't do that with configuration but:
Use External tool Pycharm feature
You can configure an external tool configuration (settings>Tools>"External Tools">Add) like this:
Then, you can assign a shortcut in keymap to run this configuration that will run Python with optimization flag on the current file.
-O for default configuration (both run/debug)
Use Run/Debug configurations>Edit configuration templates
You can't choose a configuration based on the content of a file (or not easily) or change options if it is run or debug, but you can change the default template used for configuration to include the -O
flag in the interpreter options.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论