使用的是Python 3
assert sys.version_info.major == 3
# -*- coding: utf-8 -*-
from PyQt4 import QtGui
import sys
def open_chinese_file(file_path):
with open(file_path.decode('utf-8'), 'r') as f:
data = f.read()
print(data) # 打印文件内容,确认文件已正确打开
def main():
app = QtGui.QApplication(sys.argv)
# 假设file_path是一个含有中文的文件路径,确保它是unicode编码
file_path = u'你的文件路径'.encode('utf-8')
open_chinese_file(file_path)
sys.exit(app.exec_())
if __name__ == '__main__':
main()
评论回复