subprocess.Popen(cmd)包含中文怎么办
妙音
posted @ 2017年4月22日 12:22
in python
, 4622 阅读
在windows中通过subprocess调用cmd命令行,命令中包含中文是很令人头痛的事。
由于cmd控制台用的是gbk编码,而python用的是utf-8。utf-8的字符串,在gbk编码的控制台上运行,当然会运行不了。
假如再要你兼容繁体版的windows,此时更麻烦了。还好python提供了本地化接口
- 本地化
>>> import locale >>> locale.getdefaultlocale() ('zh_CN', 'cp936')
- 示例
import locale cmd = cmd.encode(locale.getdefaultlocale()[1]) subprocess.Popen(cmd)
净土大经科注2014 百度网盘地址
2023年7月11日 19:34
was just browsing along and came upon your blog. just wanted to say good blog and this article really helped me.
2023年7月16日 05:57
The contents of the article are very original. Thanks for the work, may be an inspires for everything. I am from Imamia Quran Academy. Imamia Shia Academy has made it easier for every Shia Tajweed Quran Student to learn Shia Tajweed at his ease.
2024年12月18日 01:23
Your blog provided us with valuable information to work with. Thanks a lot for sharing. I am from Masoomeen Quran Academy. The vision of the Online Shia Quran Center is to bridge the gap between Ahle Tashi Scholars and community members globally by providing them with a platform to teach and learn the Quran.