PyCharm执行os.system出现中文乱码的问题解决方法

 1 import os,sys,io
 2 # sys.stdout = (sys.stdout.buffer,encoding='utf-8')
 3 def rule_p(n):
 4     for i in range(1,n+1):
 5         cmd_back = 'XXX' + "pfa" + str(i) + ' id ' + str(i) + ' active on'
 6         # print(cmd_back)
 7         os.system(cmd_back)
 8 n = int(input("please input a num: "))
 9 rule_p(n)
10 print('执行完成!')
C:\Users\admin\Miniconda3\python.exe E:/python/rule_p.py
please input a num: 4
'rule' �����ڲ����ⲿ���Ҳ���ǿ����еij���
���������ļ���
'rule' �����ڲ����ⲿ���Ҳ���ǿ����еij���
���������ļ���
'rule' �����ڲ����ⲿ���Ҳ���ǿ����еij���
���������ļ���
'rule' �����ڲ����ⲿ���Ҳ���ǿ����еij���
���������ļ���
执行完成!

Process finished with exit code 0

解决办法:

1 修改PyCharm配置:
2 
3 File->Settings->Editor->File Encodings
4 
5 把Global Encoding设置成GBK即可

猜你喜欢

转载自www.cnblogs.com/hujc/p/11717917.html