Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python ReferenceError:弱引用对象不再存在_Python_Python 3.x_Python 2.7_Kivy - Fatal编程技术网

Python ReferenceError:弱引用对象不再存在

Python ReferenceError:弱引用对象不再存在,python,python-3.x,python-2.7,kivy,Python,Python 3.x,Python 2.7,Kivy,我有两个文件:test.py和test.kv。当我从.kv文件调用insert\u update\u account()函数时,它会给出一个错误: File "kivy/weakproxy.pyx", line 30, in kivy.weakproxy.WeakProxy.__getattr__ (kivy/weakproxy.c:1144) File "kivy/weakproxy.pyx", line 26, in kivy.weakproxy

我有两个文件:
test.py
test.kv
。当我从
.kv
文件调用
insert\u update\u account()
函数时,它会给出一个错误:

File "kivy/weakproxy.pyx", line 30, in kivy.weakproxy.WeakProxy.__getattr__ (kivy/weakproxy.c:1144)
   File "kivy/weakproxy.pyx", line 26, in kivy.weakproxy.WeakProxy.__ref__ (kivy/weakproxy.c:1043)
 ReferenceError: weakly-referenced object no longer exists<br/>

有人能帮我吗?

在我看来,您在类
主菜单
中混合了光标
cur
和连接
con
,因为您在全局范围内定义了它,并且在类的范围内也使用相同的名称。因此,这可能是因为变量在代码中自由混合

您应该尝试在MainMenu类中显式获取连接和游标。下面的内容应该确保您每次都获得一个新的连接,并且您的代码没有将变量混合到范围之外

class MainMenu(BoxLayout):

    def __init__(self):
        super(MainMenu, self).__init__(self)
        self.con = lite.connect('test.db')
        self.cur = con.cursor()

    def display_account(self):
        self.dropdown.dismiss()
        self.remove_widgets()
        self.rvaccount = TEST()
        self.content_area.add_widget(self.rvaccount)
        self.cur.close()
        self.con.close()

    def insert_update_account(self, obj):
        self.cur.execute("UPDATE table SET test1=?, test2=? WHERE test3=?",
                    (obj.col_data[1], obj.col_data[2], obj.col_data[0]))
        self.con.commit()
        self.display_account()

我认为您的问题在于每次显示帐户时执行的
close()
,类中的
\uuuuu init\uuuuuuu
方法在哪里?由于BoxLayout有一个init,所以没有init是可以的。@ddor254每次查询执行后我都关闭了数据库连接,但仍然显示错误。我猜您想使用的是在insert\u update\u account方法中已经删除的内容。谢谢您的回复。但它给出了错误sqlite3.ProgrammingError:无法对关闭的游标进行操作
class MainMenu(BoxLayout):

    def __init__(self):
        super(MainMenu, self).__init__(self)
        self.con = lite.connect('test.db')
        self.cur = con.cursor()

    def display_account(self):
        self.dropdown.dismiss()
        self.remove_widgets()
        self.rvaccount = TEST()
        self.content_area.add_widget(self.rvaccount)
        self.cur.close()
        self.con.close()

    def insert_update_account(self, obj):
        self.cur.execute("UPDATE table SET test1=?, test2=? WHERE test3=?",
                    (obj.col_data[1], obj.col_data[2], obj.col_data[0]))
        self.con.commit()
        self.display_account()