我有一些 python 代码,我想为其禁用格式化。
我知道在 java 和 intellij 中你可以通过这样做来实现:
// @formatting:off
code that doesn't get formatted
// @formatting:on
python代码和pycharm有没有类似的东西?
请您参考如下方法:
这是你应该做的。首先,在 Preferences 下面的注释中启用格式化程序标记;
Preferences -> Code Style -> Formatter Control -> 勾选 Enable formatter markers in comments
然后放置你的格式化标记,例如;
# @formatter:off
df = pd.DataFrame({'height': height, 'weight': weight}, columns=['height', 'weight'])
df.plot.scatter(x='height', y='weight')
#@formatter:on
注意 # 用于行注释。
顺便说一下,您的注释标记在 python 源代码中似乎不正确。我在 PyCharm 2018.3.4(社区版)上试过这个并且工作正常。
进一步引用:https://www.jetbrains.com/help/pycharm/settings-code-style.html#formatter_options
希望这对您有所帮助。
