[Python-ideas] Implicit string literal concatenation considered harmful?
M.-A. Lemburg
mal at egenix.com
Tue May 14 19:43:39 CEST 2013
On 14.05.2013 19:24, Mark Dickinson wrote:
> On Sat, May 11, 2013 at 6:24 PM, M.-A. Lemburg <mal at egenix.com> wrote:
>
>> On 11.05.2013 19:05, Christian Tismer wrote:
>>> I think a simple stripping of white-space in
>>>
>>> text = s"""
>>> leftmost column
>>> two-char indent
>>> """
>>>
>>> would solve 95 % of common indentation and concatenation cases.
>>> <snipped>
>>
>
>> This is not a good solution for long lines where you don't want to
>> have embedded line endings. Taken from existing code:
>>
>> _litmonth = ('(?P<litmonth>'
>> 'jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec|'
>> 'mär|mae|mrz|mai|okt|dez|'
>> 'fev|avr|juin|juil|aou|aoû|déc|'
>> 'ene|abr|ago|dic|'
>> 'out'
>> ')[a-z,\.;]*')
>>
>> or
>> raise errors.DataError(
>> 'Inconsistent revenue item currency: '
>> 'transaction=%r; transaction_position=%r' %
>> (transaction, transaction_position))
>>
>
> Agreed. I use the implicit concatenation a lot for exception messages like
> the one above; we also tend to keep line length to 80 characters *and* use
> nice verbose exception messages. I could live with adding the extra '+'
> characters and parentheses, but I think it would be a net loss of
> readability.
>
> The _litmonth example looks like a candidate for re.VERBOSE and a
> triple-quoted string, though.
It's taken out of context, just to demonstrate some real world
example of how long strings are broken down to handy 80 char
code lines.
The _litmonth variable is used as component to build other REs
and those typically also contain (important) whitespace,
so re.VERBOSE won't work.
--
Marc-Andre Lemburg
eGenix.com
Professional Python Services directly from the Source (#1, May 14 2013)
>>> Python Projects, Consulting and Support ... http://www.egenix.com/
>>> mxODBC.Zope/Plone.Database.Adapter ... http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/
________________________________________________________________________
2013-05-07: Released mxODBC Zope DA 2.1.2 ... http://egenix.com/go46
2013-05-06: Released mxODBC 3.2.3 ... http://egenix.com/go45
::::: Try our mxODBC.Connect Python Database Interface for free ! ::::::
eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48
D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
Registered at Amtsgericht Duesseldorf: HRB 46611
http://www.egenix.com/company/contact/
More information about the Python-ideas
mailing list