Re: Unexpected string behaviour: txt = 'this' ' works'

2009-02-11 Thread Steven D'Aprano
On Wed, 11 Feb 2009 12:57:31 -0800, bearophileHUGS wrote: > Jason: >> It's such a minor optimization, that you probably wouldn't see any >> effect on your program. > from dis import dis def f(): > ... return 'This is ' + 'an example.' ... dis(f) > 2 0 LOAD_CONST

Re: Unexpected string behaviour: txt = 'this' ' works'

2009-02-11 Thread bearophileHUGS
Jason: > It's such a minor optimization, that you probably wouldn't see any > effect on your program. >>> from dis import dis >>> def f(): ... return 'This is ' + 'an example.' ... >>> dis(f) 2 0 LOAD_CONST 3 ('This is an example.') 3 RETURN_VALUE Bye, bea

Re: Unexpected string behaviour: txt = 'this' ' works'

2009-02-11 Thread Jason
On Feb 11, 5:16 am, bearophileh...@lycos.com wrote: > christopher.saun...@durham.ac.uk (c d saunter): > > >I assume it is a feature of the compiler.< > > Yes it's a bug-prone antifeature that's probably a relic from C that > doesn't have a concatenation operator among strings as Python does > (+).

Re: Unexpected string behaviour: txt = 'this' ' works'

2009-02-11 Thread bearophileHUGS
christopher.saun...@durham.ac.uk (c d saunter): >I assume it is a feature of the compiler.< Yes it's a bug-prone antifeature that's probably a relic from C that doesn't have a concatenation operator among strings as Python does (+). So in Python it saves you to use + at the cost of possible bugs.

Re: Unexpected string behaviour: txt = 'this' ' works'

2009-02-11 Thread c d saunter
Bruno Desthuilliers (bruno.42.desthuilli...@websiteburo.invalid) wrote: : c d saunter a écrit : : > I did a double take when debugging an error the other day. My : > problem was missing out a comma when building a list of strings. : > : > Much to my surprise the offending code still executed to c

Re: Unexpected string behaviour: txt = 'this' ' works'

2009-02-11 Thread Bruno Desthuilliers
c d saunter a écrit : I did a double take when debugging an error the other day. My problem was missing out a comma when building a list of strings. Much to my surprise the offending code still executed to cause problems later on: txt = 'this', 'works' print txt ('this', 'works') # As expect

Re: Unexpected string behaviour: txt = 'this' ' works'

2009-02-11 Thread Quentin Gallet-Gilles
*Literal* string concatenation has always been a part of Python : http://docs.python.org/reference/lexical_analysis.html#string-literal-concatenation On Wed, Feb 11, 2009 at 12:06 PM, c d saunter < christopher.saun...@durham.ac.uk> wrote: > I did a double take when debugging an error the other d

Unexpected string behaviour: txt = 'this' ' works'

2009-02-11 Thread c d saunter
I did a double take when debugging an error the other day. My problem was missing out a comma when building a list of strings. Much to my surprise the offending code still executed to cause problems later on: >>> txt = 'this', 'works' >>> print txt ('this', 'works') # As expected >>> txt = 'this