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
Sqlite 访问原始数据中的变量字段/列_Sqlite_Web2py - Fatal编程技术网

Sqlite 访问原始数据中的变量字段/列

Sqlite 访问原始数据中的变量字段/列,sqlite,web2py,Sqlite,Web2py,我喜欢在SQL中访问一行的变量列/字段,怎么做? 例如,在web2py x=db(db.table.name==“john”).select().last().job1将为您提供名称等于“john”的行的作业字段。但假设我想在另一个条件下为x选择其他字段/列,如 if conditon1: column = job1 if condition2: column = job2 x = db(db.table.name=="john").select().last().column 如何

我喜欢在SQL中访问一行的变量列/字段,怎么做? 例如,在web2py x=db(db.table.name==“john”).select().last().job1将为您提供名称等于“john”的行的作业字段。但假设我想在另一个条件下为x选择其他字段/列,如

if conditon1:
  column = job1
if condition2: 
  column = job2
x = db(db.table.name=="john").select().last().column
如何执行此操作?

使用内置python函数


对象可以是,因此您可以执行以下操作:

x = db(db.table.name=="john").select().last()[column]

无需使用
getatr
,因为
row
对象充当字典。看见
x = db(db.table.name=="john").select().last()[column]