python获取自己的路径
python取文件后缀

subprocess.Popen(cmd)包含中文怎么办

妙音 posted @ 2017年4月22日 12:22 in python , 4528 阅读
在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 百度网盘地址

http://pan.baidu.com/s/1gfaHvwv

Avatar_small
Live Draw SGP 说:
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.

Avatar_small
Imamia Quran Academy 说:
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.

 


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter