PYQT 和读取文件到 Qtextedit

PYQT and reading file to Qtextedit

我正在使用 PyQt4,但在打开文本文件并将其显示到 Qtextedit 时遇到问题。 "print f + " this needs to go in textedit" 打印它在那里,但 open 说它不是。任何帮助将不胜感激。

def convertDirectory(self):
    directoryPath = self.selectFilecsvtoxml()
    cmd = ('python loginformationExtractor.py '
           +str(directoryPath))
    print cmd + "   this is executable command"
    os.system(cmd)

    for file_name in os.listdir(directoryPath):
        print (directoryPath) + "****" + file_name

        if file_name.endswith(".txt"):
            f = file_name
            print f + "  this needs to go in textedit"

            readMe = open(f,'r').read()
            self.textEdit.setText(readMe)

我的error/printout:

/Users/eeamesX/work/data/releaseOct27****UUIDreadout.txt
UUIDreadout.txt  this needs to go in textedit
Traceback (most recent call last):
  File "/Users/eeamesX/PycharmProjects/Workmain/windows.py", line 2792, in convertDirectory
    readMe = open(f,'r').read()
IOError: [Errno 2] No such file or directory: 'UUIDreadout.txt'
def convertDirectory(self):
    directoryPath = self.selectFilecsvtoxml()
    cmd = ('python loginformationExtractor.py '
           +str(directoryPath))
    print cmd + "   this is executable command"
    os.system(cmd)

    for file_name in os.listdir(directoryPath):
        print (directoryPath) + "****" + file_name

        if file_name.endswith(".txt"):
            f = os.path.join(directoryPath, file_name)
            print f + "  this needs to go in textedit"

            readMe = open(f,'r').read()
            self.textEdit.setText(readMe

我想你忘记添加目录路径文件了。