我有一个很长的查询。我想在Python中分成几行。在JavaScript中使用的方法是使用几个句子,并将它们与一个+运算符结合起来(我知道,也许这不是最有效的方法,但是在这个阶段我并不关心性能,只是代码的可读性) 。例:
var long_string = 'some text not important. just garbage to' + 'illustrate my example';我尝试了在Python中做类似的事情,但它没有工作,所以我用来\分割长字符串。但是,我不确定这是否是唯一的/最好的/ pythonicest的方式。看起来很尴尬。实际代码:
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相似问题