解決pycharm下os.system執(zhí)行命令返回有中文亂碼的問(wèn)題
如下所示:
source = ['C:\\Users\\admin\\Desktop\\pythonLearning'] target_dir = 'C:\\Users\\admin\\Desktop' print(time.strftime('%Y%m%d%H%M%S')) target = target_dir + os.sep + time.strftime('%Y%m%d%H%M%S') + '.zip' if not os.path.exists(target_dir): os.mkdir(target_dir) zip_command = 'HaoZipC a {0} {1}'.format(target, ' '.join(source)) type = sys.getfilesystemencoding() print('類型為:', type) print('Zip command is:') print(zip_command) print('Running:') result = os.system(zip_command) if result == 0: print('Successful backup to', target) else: print('Backup FAILED')
控制臺(tái)返回:
20170811100310
類型為: utf-8
Zip command is:
HaoZipC a C:\Users\admin\Desktop\20170811100310.zip C:\Users\admin\Desktop\pythonLearning
Running:
����ɨ���ļ�...
����ѹ���ĵ� C:\Users\admin\Desktop\20170811100310.zip
��ѹ���ļ���C:\Users\admin\Desktop\pythonLearning\byte-of-python-chinese-edition.pdf
��ѹ���ļ��� C:\Users\admin\Desktop\pythonLearning\byte-of-python.pdf
��ѹ���ļ��� C:\Users\admin\Desktop\pythonLearning\python�˹�����.png
解決方法:
將Global Encoding設(shè)置為gbk,即可正常顯示,如下:
20170811100615
類型為: utf-8
Zip command is:
HaoZipC a C:\Users\admin\Desktop\20170811100615.zipC:\Users\admin\Desktop\pythonLearning
Running:
正在掃描文件...
創(chuàng)建壓縮文檔 C:\Users\admin\Desktop\20170811100615.zip
正壓縮文件:C:\Users\admin\Desktop\pythonLearning\byte-of-python-chinese-edition.pdf
原因據(jù)說(shuō)是因?yàn)镮DE編碼不能設(shè)置為utf-8,需要設(shè)置為gbk,因?yàn)檫@個(gè)控制臺(tái)的代碼需要和windows保持一致。
以上這篇解決pycharm下os.system執(zhí)行命令返回有中文亂碼的問(wèn)題就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
Python網(wǎng)絡(luò)爬蟲(chóng)神器PyQuery的基本使用教程
這篇文章主要給大家介紹了關(guān)于Python網(wǎng)絡(luò)爬蟲(chóng)神器PyQuery的基本使用教程,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)使用PyQuery具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧。2018-02-02Django框架創(chuàng)建mysql連接與使用示例
這篇文章主要介紹了Django框架創(chuàng)建mysql連接與使用,簡(jiǎn)單介紹了Linux環(huán)境下mysql的安裝,并結(jié)合實(shí)例形式分析了Django框架基于第三方庫(kù)pymysql連接mysql數(shù)據(jù)庫(kù)相關(guān)操作技巧,需要的朋友可以參考下2019-07-07python實(shí)現(xiàn)信號(hào)時(shí)域統(tǒng)計(jì)特征提取代碼
今天小編就為大家分享一篇python實(shí)現(xiàn)信號(hào)時(shí)域統(tǒng)計(jì)特征提取代碼,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-02-02pyodps中的apply用法及groupby取分組排序第一條數(shù)據(jù)
這篇文章主要介紹了pyodps中的apply用法及groupby取分組排序第一條數(shù)據(jù),問(wèn)綻放圍繞主題展開(kāi)詳細(xì)的內(nèi)容介紹,具有一定的參考價(jià)值需要的小伙伴可以參考一下2022-05-05