有没有办法更改 Pydev 中所有运行配置的默认编码?
关于优点或缺点/在 python 2 中使用 sys.setdefaultencoding(...) 的邪恶 .x 我正在使用 PyDev,我希望拥有默认的“开箱即用”python 行为(US-ASCII 作为默认(非)编码),因为我觉得这更安全(我不喜欢site_customize.py 方法),即使更费力。
当我使用 PyDev (特别是运行单元测试)时,它默认调用 sys.setdefaultencoding('UTF-8')。其他答案建议在每个“运行配置”通用选项卡中将编码设置更改为“US-ASCII”。
我想将 pydev(每个工作区)中所有运行配置的默认更改为“US-ASCII”,或者至少在全局范围内将一个 Python 解释器更改为“US-ASCII”。有办法做到这一点吗?
研究了实现:Pydev 使用 PYDEV_CONSOLE_ENCODING 环境变量来获取编码(位于 org.python.pydev 插件中的 site_customize.py 文件中)。然而,这似乎是通过“运行配置”下拉列表中的运行对话框的设置来设置的。默认值是“继承 - UTF-8”,但我没有找到任何地方可以在 pydev 的设置中更改它。我尝试在各个地方设置环境变量 PYDEV_CONSOLE_ENCODING,但这尚未到达 site_customize.py (而是从对话框选项卡上的编码设置中读取值)。
There has been some discussion of the merits or demerits/evilness of using sys.setdefaultencoding(...) in python 2.x I'm using PyDev and I want to have the default 'out of the box' python behaviour (US-ASCII as default (non-)encoding), as I feel this is safer (I don't like the site_customize.py approach), even if more laborious.
When I'm using PyDev (particularly for running unittests) it be defaults calls sys.setdefaultencoding('UTF-8'). Other answers have recommended changing the encoding setting to 'US-ASCII' in each 'run configurations' Common tab.
I would like to change the default for all run configurations to 'US-ASCII' across pydev (per workspace) or at least globally for one Python interpreter. Is there a way to do this?
Having looked into the implementation: Pydev uses a PYDEV_CONSOLE_ENCODING environment variable to get the encoding (this is within the site_customize.py file in the org.python.pydev plugin). However this seems to be set from the setting of the run-dialog in the Run configurations drop down. The default says "inherited - UTF-8" but I haven't found anywhere to change this in pydev's settings. I've tried setting the environment variable PYDEV_CONSOLE_ENCODING in various places, but this hasn't got through to site_customize.py (instead it reads the value from the Encoding setting on the dialog tab).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在“窗口”>“更改默认编码”偏好>一般>工作区>文本文件编码(设置为其他> us-ascii)。
You can change the default encoding at window > preferences > general > workspace > text file encoding (set it to other > us-ascii).