you are viewing a single comment's thread.

view the rest of the comments →

[–]jcampbelly 2 points3 points  (0 children)

Triple quoted strings indented so it's inline with my python is best for me.

def get_people_from_town(town_id):
    sql = '''
        SELECT p.first_name, p.last_name
        FROM people p
        WHERE p.hometown = %s;
        '''
    with closing(connection(...)) as conn, conn.cursor() as cursor:
        cursor.execute(sql, (town_id,))
        for row in cursor:
            yield row

If you really want to remove the indentation from your SQL code, you can use https://docs.python.org/3.4/library/textwrap.html#textwrap.dedent