Pythonic way to create a long multi-line string

后端 未结 27 2024
滥情空心
滥情空心 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 01:02

    You can also place the sql-statement in a seperate file action.sql and load it in the py file with

    with open('action.sql') as f:
       query = f.read()
    

    So the sql-statements will be separated from the python code. If there are parameters in the sql statement which needs to be filled from python, you can use string formating (like %s or {field})

提交回复
热议问题