簡體   English   中英

PYQT並將文件讀取到Qtextedit

[英]PYQT and reading file to Qtextedit

我正在使用PyQt4,無法打開文本文件並將其顯示給Qtextedit。 “ print f +“這需要在textedit中進行”將其打印在此處,但公開表示沒有,任何幫助將不勝感激。

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

我認為您忘記添加目錄路徑文件。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM