在我的 Python 脚本中,我有一个永远持续下去的 SQL 语句,如下所示:
query = """
SELECT * FROM
many_many
tables
WHERE
this = that,
a_bunch_of = other_conditions
"""
让它像单行一样阅读的最佳方法是什么?我试过这个:
def formattedQuery(query):
lines = query.split('\n')
for line in lines:
line = line.lstrip()
line = line.rstrip()
return ' '.join(lines)
它确实删除了换行符,但没有从缩进中删除空格。请帮忙!