<>强如下所示:强>
源=[' C: \ \ \ \管理\ \用户桌面\ \ pythonLearning”) target_dir=' C: \ \ \ \管理\ \用户桌面的 打印(time.strftime (Y ' % % m % d % H % m % S ')) 目标=target_dir +操作系统。9 + time.strftime (Y ' % % m % d % H % m % S ') +“zip” 如果不是os.path.exists (target_dir): os.mkdir (target_dir) zip_command=癏aoZipC {0} {1}”。格式(目标”、“. join(源)) 类型=sys.getfilesystemencoding () 打印(“类型为:“,类型) 打印(“Zip命令:”) 打印(zip_command) print('运行:') 结果=os.system (zip_command) 如果结果==0: 打印(“成功备份”,目标) 其他: 打印(备份失败的) >之前控制台返回:
20170811100310
类型为:utf - 8
压缩命令是:
HaoZipC C:\Users\admin\Desktop\ 20170811100310。zip C:\Users\admin\Desktop\ pythonLearning
运行:
& # 65533; & # 65533; & # 65533; & # 65533; & # 616; & # 65533; & # 65533; & # 65533; & # 316; & # 65533;…
& # 65533; & # 65533; & # 65533; & # 65533; & # 1145; & # 65533; & # 65533; & # 65533; & # 309; & # 65533;C:\Users\admin\Desktop\ zip
20170811100310.& # 65533; & # 65533; & # 1145; & # 65533; & # 65533; & # 65533; & # 316; & # 65533; & # 65533; & # 65533; C: \ \ admin用户桌面\ \ pythonLearning \ byte-of-python-chinese-edition.pdf
& # 65533; & # 65533; & # 1145; & # 65533; & # 65533; & # 65533; & # 316; & # 65533; & # 65533; & # 65533;C:\Users\admin\Desktop\ pythonLearning \ byte-of-python.pdf
& # 65533; & # 65533; & # 1145; & # 65533; & # 65533; & # 65533; & # 316; & # 65533; & # 65533; & # 65533;C:\Users\admin\Desktop\ pythonLearning \ python # 65533; & # 761; & # 65533; & # 65533; & # 65533; & # 65533; & # 65533; . png
将全球编码设置为gbk,即可正常显示,如下:
20170811100615
类型为:utf - 8
Zip命令是:
HaoZipC C:\Users\admin\Desktop\ 20170811100615。zipC: \用户桌面\ \ admin \ pythonLearning
运行:
正在扫描文件…创建压缩文档C:\Users\admin\Desktop\ zip
20170811100615.正压缩文件:C: \ \ admin用户桌面\ \ pythonLearning \ byte-of-python-chinese-edition.pdf
原因据说是因为IDE编码不能设置为utf - 8,需要设置为gbk,因为这个控制台的代码需要和windows保持一致。
以上这篇解决pycharm下os.system执行命令返回有中文乱码的问题就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。
解决pycharm下os.system执行命令返回有中文乱码的问题