pyqt 通过notepad打开中文文件

来源:互联网 发布:linux安装rpm文件 编辑:程序博客网 时间:2024/06/06 18:07


在qtreeview中通过:

        indexItem = self.model.index(index.row(), 0, index.parent())        filePath = self.model.filePath(indexItem)

可以获得文件路径,然后通过

        if(os.path.isfile(u''+str(unicode(filePath)).decode('utf-8'))):            import subprocess            subprocess.call(['notepad.exe', filepath])

即可打开文件,但是这只限于英文的路径和英文的文件

对于中文的解决办法其实很简单

只需要在头部添加

# -*- coding:utf-8 -*-

然后打开文件

subprocess.call(['notepad.exe', (u''+str(unicode(filePath))).encode('gbk')])

即可打开通过windows下的notepad打开文件

0 0
原创粉丝点击