[Python-Dev] PEP 30XZ: Simplified Parsing

skip at pobox.com skip at pobox.com
Thu May 3 03:45:30 CEST 2007

    Raymond> [Skip]
    >> I use it all the time.  For example, to build up (what I consider to be)
    >> readable SQL queries:
    >> rows = self.executesql("select cities.city, state, country"
    >>                        "    from cities, venues, events, addresses"
    >>                        "    where cities.city like %s"
    >>                        "      and events.active = 1"
    >>                        "      and venues.address = addresses.id"
    >>                        "      and addresses.city = cities.id"
    >>                        "      and events.venue = venues.id",
    >>                        (city,))

    Raymond> I find that style hard to maintain.  What is the advantage over
    Raymond> multi-line strings?

    Raymond>  rows = self.executesql('''
    Raymond>     select cities.city, state, country
    Raymond>     from cities, venues, events, addresses
    Raymond>     where cities.city like %s
    Raymond>           and events.active = 1
    Raymond>           and venues.address = addresses.id
    Raymond>           and addresses.city = cities.id
    Raymond>           and events.venue = venues.id
    Raymond>     ''', 
    Raymond>     (city,))

Maybe it's just a quirk of how python-mode in Emacs treats multiline strings
that caused me to start doing things this way (I've been doing my embedded
SQL statements this way for several years now), but when I hit LF in an open
multiline string a newline is inserted and the cursor is lined up under the
"r" of "rows", not under the opening quote of the multiline string, and not
where you chose to indent your example.  When I use individual strings the
parameters line up where I want them to (the way I lined things up in my
example).  At any rate, it's what I'm used to now.


More information about the Python-Dev mailing list