Illegal literal or not?

Bengt Richter bokr at oz.net
Sat Jan 25 20:50:05 EST 2003


On Sat, 25 Jan 2003 23:25:51 +0100, Laura Creighton <lac at strakt.com> wrote:

>> Gerrit Holl wrote:
>> > 
>> > Peter Hansen schreef op zaterdag 25 januari om 20:32:03 +0000:
>> > > Mel Wilson wrote:
>> > > > >>> print "'" + '"' + "Let's try this!" + '"' + ', they said.' + "'"
>> > > > >>> print ''.join (["'", '"', "Let's try this!", '"', ', they said.', "
>> '"])
>> > 
>> > > >>> print '"'.join(["'", "Let's try this!", ", they said.'"])
>> > > '"Let's try this!", they said.'
>> > 
>> > >>> print "'"'"'"Let's try this!"'"'', they said.'"'"
>> > '"Let's try this!", they said.'
>> > 
>> > :)
>> 
>> Oooohh, very slick.  Automatic concatenation of adjacent string
>> literals. :-)
>> 
>> <hat mode="doffed"/>
>> 
>> -Peter
>> -- 
>> http://mail.python.org/mailman/listinfo/python-list
>
>I think that it is more readable like this:
>
>>>> print "'" '"' "Let's try this!" '"' ', they said.' "'"
>'"Let's try this!", they said.'

I think it's even clearer if you isolate the data of interest from the quoting
as much as possible. E.g., (a little extreme perhaps, but very literally readable):

 >>> print """
 ...
 ... '"Let's try this!", they said.'
 ...
 ... """[2:-2] # exclude leading and trailing blank lines
 '"Let's try this!", they said.'

Regards,
Bengt Richter




More information about the Python-list mailing list