我有一个非常长的查询语句,我想在Python中将其拆分成几行。在JavaScript中这样做的一种方法是使用几个句子并使用 +
运算符将它们连接起来(我知道,也许这不是最有效的方法,但在这个阶段我并不真正关心性能,只关心代码的易读性)。例如:
var long_string = 'some text not important. just garbage to' +
'illustrate my example';
我曾试过在Python中做类似的事情,但它没有起作用,所以我使用了\
来拆分长字符串。但是,我不确定这是否是唯一/最好/最符合Python风格的方法。它看起来很笨拙。
query = 'SELECT action.descr as "action", '\
'role.id as role_id,'\
'role.descr as role'\
'FROM '\
'public.role_action_def,'\
'public.role,'\
'public.record_def, '\
'public.action'\
'WHERE role.id = role_action_def.role_id AND'\
'record_def.id = role_action_def.def_id AND'\
'action.id = role_action_def.action_id AND'\
'role_action_def.account_id = ' + account_id + ' AND'\
'record_def.account_id=' + account_id + ' AND'\
'def_id=' + def_id