line continuations with backslash

Bengt Richter bokr at accessone.com
Mon Aug 27 13:20:32 EDT 2001


On 27 Aug 2001 05:30:50 -0700, Paul Rubin <phr-n2001 at nightsong.com> wrote:

>"Tim Peters" <tim.one at home.com> writes:
>> > so why not this then:
>> >
>> >     x = long("123"
>> >              "456"
>> >              "789")
>> >
>> > which saves all the splitting and joining and is (nearly) as readable?
>> 
>> Because it's not as readable, or as easy to edit.  The cost of splitting and
>> joining on one-shot initialization code is insignificant, most likely too
>> small to measure.
>
>The cpu costs of splitting and joining at initialization are
>insignificant but writing out the numbers in ascii instead of in
>marshalled form makes the .pyc files somewhat bigger (a few hundred
>bytes in this situation).  That shouldn't be disastrous but it strikes
>me as unnecessary bloat.  Being able to split literals with backslash
>wouldn't mess up the language in any way I can easily see.
>
>Btw, the target computer is a handheld with limited memory and whose
>file system is entirely in ram, so burning space unnecessarily in the
>.pyc hurts a little more than it would on a pc with gigabytes of disk
>available.
 >>> dis.dis(compile("'123' '456'",'','eval'))
           0 SET_LINENO               0
           3 LOAD_CONST               0 ('123456')
           6 RETURN_VALUE
 >>> marshal.dumps(compile("'123' '456'",'','eval'))
 'c\x00\x00\x00\x00\x01\x00\x00\x00s\x07\x00\x00\x00\x7f\x00\x00d\x00\x00S(\x01\x00\x00\x00
 s\x06\x00\x00\x00123456(\x00\x00\x00\x00(\x00\x00\x00\x00(\x00\x00\x00\x00(\x00\x00\x00\x0
 0s\x00\x00\x00\x00s\x01\x00\x00\x00?\x00\x00s\x00\x00\x00\x00'
 >>>

The '123' '456' seems to be folded in the tokenizer,
not passed on as tokens for a join op.

I do wonder if also letting it ignore
'\\'+os.linesep (assuming normalized EOLs) would break anything.



More information about the Python-list mailing list