Hot to split string literals that will across two or more lines ?

Fredrik Lundh fredrik at pythonware.com
Wed Nov 23 04:37:44 EST 2005


Mohammad Jeffry wrote:

> I can always do this :-
> ---------------------------------------------------------------------------------
> #!/usr/bin/python
>
>
> def print_sql():
>     sql = '''aaaaaaaaaaaaaaaaaaaaaaa
> bbbbbbbbbbbbbbbbbbbbbbb'''.replace("\n","")
>     print sql
>
> print_sql()
>
> ---------------------------------------------------------------------------------

    sql = (
        'aaaaaaaaaaaaaaaaaaaaaaa'
        'bbbbbbbbbbbbbbbbbbbbbbb'
    )
    print sql

or, perhaps more realistic:

    cursor.execute(
        'aaaaaaaaaaaaaaaaaaaaaaa'
        'bbbbbbbbbbbbbbbbbbbbbbb',
        a, b, c
    )

e.g.

    cursor.execute(
        'select * from foo'
        ' where bar=%s'
        ' limit 100',
        bar
    )


</F>






More information about the Python-list mailing list