如何为运行而非调试应用优化标志以获取默认配置?

huangapple go评论57阅读模式
英文:

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.

如何为运行而非调试应用优化标志以获取默认配置?

huangapple
  • 本文由 发表于 2023年2月8日 18:49:18
  • 转载请务必保留本文链接:https://go.coder-hub.com/75384689.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定