Pythonic way to create a long multi-line string

后端 未结 27 1650
滥情空心
滥情空心 2020-11-22 00:47

I have a very long query. I would like to split it in several lines in Python. A way to do it in JavaScript would be using several sentences and joining them with a +<

27条回答
  •  爱一瞬间的悲伤
    2020-11-22 00:52

    Generally, I use list and join for multi-line comments/string.

    lines = list()
    lines.append('SELECT action.enter code here descr as "action", ')
    lines.append('role.id as role_id,')
    lines.append('role.descr as role')
    lines.append('FROM ')
    lines.append('public.role_action_def,')
    lines.append('public.role,')
    lines.append('public.record_def, ')
    lines.append('public.action')
    query = " ".join(lines)
    

    you can use any string to join all this list element like '\n'(newline) or ','(comma) or ''(space)

    Cheers..!!

提交回复
热议问题