[code-quality] [Python-ideas] Implicit string literal concatenation considered harmful?
Rigel
zedr at zedr.com
Sat May 11 16:28:52 CEST 2013
On Sat, May 11, 2013 at 1:12 PM, Alexandre Fayolle ML
<afayolle.ml at free.fr>wrote:
>
> I'll typically use such wrapping on SQL statements:
>
> cursor.execute('SELECT foo, bar FROM mytable '
>
> 'WHERE baz = %(baz)s',
>
> {'baz': baz})
>
> I prefer to use string concatenation using the 'addition' operator, which
makes it more explicit:
cursor.execute('SELECT foo, bar FROM mytable ' +
'WHERE baz = %(baz)s',
{'baz': baz})
At compile time, they are implemented in the same way:
>>> dis.dis(lambda: 'a' + 'a')
2 0 LOAD_CONST 2 ('aa')
3 RETURN_VALUE
>>> dis.dis(lambda: 'a' 'a')
2 0 LOAD_CONST 1 ('aa')
3 RETURN_VALUE
Rigel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/code-quality/attachments/20130511/ff059df0/attachment.html>
More information about the code-quality
mailing list