我正在使用PyQt4,无法打开文本文件,并将其显示给Qtextedit。 "打印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'
答案 0 :(得分:1)
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
I think you forgot to add dir path file.