semi-concatenated strings

Steven Majewski sdm7g at Virginia.EDU
Fri May 31 12:12:01 EDT 2002


On 31 May 2002, Grant Griffin wrote:

> Better yet would be if the parser would automatically concatenate incomplete
> expressions (as identified by a line that ends with an operator), much as it
> automatically concatenates incomplete list and dictionary initialization
> statements.  Then your example would become:
>
>     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,))
>
> which doesn't look so bad.  (But then again, without the backslash it's less
> explicit <wink>.)

The above *ought* to work.
The hanging "+" alone doesn't do the trick, but the hanging "(" does --
the parser knows it needs a matching ")" :

>>> ( "one" +
...   "two" +
...   "three" )
'onetwothree'


( Of course, it will work with the parends but *without* the "+" too! )

-- Steve Majewski





More information about the Python-list mailing list