ValueError:对已关闭文件的I / O操作
嗨,我的代码中出现此错误。我已经尝试使用Google搜索,但我知道错误的含义,但我不明白为什么会收到此错误。我仍在学习python,所以这可能是一个基本错误。
jTable_ConnectionsDetails.setAutoCreateRowSorter(true);
jTable_ConnectionsDetails.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
},
new String [] {
"Connection Name", "Conn Type", "Host", "Port", "Service Name", "User", "profilename", "Password", "desc"
}
) {
Class[] types = new Class [] {
java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
};
public Class getColumnClass(int columnIndex) {
return types [columnIndex];
}
});
jTable_ConnectionsDetails.setCellSelectionEnabled(true);
jTable_ConnectionsDetails.getModel().addTableModelListener(new TableModelListener() {
public void tableChanged(TableModelEvent e) {
ColumnsAutoSizer.sizeColumnsToFit(jTable_ConnectionsDetails);
}
});
jScrollPane_ConnectionsDataTable.setViewportView(jTable_ConnectionsDetails);
此部分发生错误:
for line in file:
if line == tekstNaamLogin:
file.close()
file2 = open (filename2, 'r+')
for line in file2:
if line == tekstWwLogin:
weergaveinlog = Label(root, text = "Succesvol ingelogd!" + tekstNaamLogin)
weergaveinlog.grid(row=4, sticky=W, column =1)
print ("Succesvol ingelogd als: " + tekstNaamLogin)
file2.close()
time.sleep(2)
vergeetinlog()
weergaveinlog.grid_forget()
start()
else:
print ("Wachtwoord onjuist!")
else:
print ("Gebruikersnaam onjuist!")
file = open (filename, 'r+')
print ("Uw gebruikersnaam is: " + line)
file.close()
我只是不明白怎么了,因为文件2会在读取之前打开。
感谢帮助