PYQT和读取文件到Qtextedit

问题描述:

我使用PyQt4并无法打开文本文件,并将其显示到Qtextedit。 “打印F +”这需要在文本编辑去”,它的存在,但开说,这不是任何帮助,将不胜感激版画PYQT和读取文件到Qtextedit

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) 

我的错误/打印输出:。

/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 

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

+0

尝试和努力,谢谢! – Anekdotin