ich bin beim Öffnen einer normalen Text-Datei etwas verwirrt. Hier zunächst mein Code.
Code: Alles auswählen
def read_licence(self):
licence_file = None
setting_folder = unicode(os.path.abspath(os.path.join('licences', 'Licence GPL2.txt')), "UTF-8")
try:
licence_file = open(setting_folder).read()
self.ui_pp_about.textEditLicence.setText(licence_file)
print("\n\nRead licence-file from: " + setting_folder)
except (IOError, ValueError):
QMessageBox.information(None, 'ERROR', licence_file.errorString())
print "An I/O error or a ValueError occurred"
except:
print "An unexpected error occurred"
raise
finally:
if licence_file is not None:
licence_file.close()
Schließt Python denn nach dem Lesen (read()) die Datei selbst, oder muss ich mich als Programmierer selbst darum kümmern?File "D:\Dan\Python\project_xarphus\files\modules_ui\ui_pp_about.py", line 115, in read_licence
licence_file.close()
AttributeError: 'str' object has no attribute 'close'