Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.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 Sqlite3将获取的记录分配到变量中_Python_Sqlite - Fatal编程技术网

Python Sqlite3将获取的记录分配到变量中

Python Sqlite3将获取的记录分配到变量中,python,sqlite,Python,Sqlite,我在网上研究过这个话题,但还没有找到解决问题的办法。最接近的是这个网站上的一个问题: 然而,它使用整数转换它,就像它使用数字一样,然而这不能用我的数据来完成 这是我当前的代码,基于前面的问题: def View_Trainer_Record(self, index): self.cur.execute('SELECT * FROM Trainers WHERE rowid=?', (index+1,)) global Record

我在网上研究过这个话题,但还没有找到解决问题的办法。最接近的是这个网站上的一个问题:

然而,它使用整数转换它,就像它使用数字一样,然而这不能用我的数据来完成

这是我当前的代码,基于前面的问题:

   def View_Trainer_Record(self, index):
            self.cur.execute('SELECT * FROM Trainers WHERE rowid=?', (index+1,))

            global Record
            Record = self.cur.fetchone()
            (Name, TrainerID, Postcode, Age, Gender, Password) = tuple(Record[0])
            print ("Record")
            print (Record)
            print ("Name")
            print (Name)
            print ("TrainerID")
            print (TrainerID)
            print ("Postcode")
            print (Postcode)
            print ("Age")
            print (Age)
            print ("Gender")
            print (Gender)
            print ("Password")
            print (Password)
这就是错误:

TypeError: 'int' object is not subscriptable

我要问的问题是,我如何才能将这个获取的记录中的每一部分拆分为单独的变量,以便稍后在另一个类中调用。

尝试
元组(记录)
,而不是记录[0],它将选择您选择的第一列。如果使用
名称、TrainerID、邮政编码、年龄、性别,Password=Record
谢谢我删除了[0]并打印了它为什么您的记录是全局的?您可以使用
返回记录返回值
元组
或从
列表中解包值
与它们都是iTerable大致相同。