def debugLogSQL(sql):
    print(' '.join([line.strip() for line in sql.splitlines()]).strip())
sql = """
    select field1, field2, field3, field4
    from table"""
if debug:
    debugLogSQL(sql)
Python SQL query string formatting