Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #48888

Re: n00b question on spacing

From Terry Reedy <tjreedy@udel.edu>
Subject Re: n00b question on spacing
Date 2013-06-21 18:33 -0400
References <CAJ=2b07ETuSuo2+3Xu6vMOJA+q1JwUFTezO3LaYLG8wXd+FLBQ@mail.gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.3673.1371854012.3114.python-list@python.org> (permalink)

Show all headers | View raw


On 6/21/2013 5:17 PM, Yves S. Garret wrote:
> Hi, I have a question about breaking up really long lines of code in Python.
>
> I have the following line of code:
> log.msg("Item wrote to MongoDB database %s/%s" %(settings['MONGODB_DB'],
> settings['MONGODB_COLLECTION']), level=log.DEBUG, spider=spider)
>
> Given the fact that it goes off very far to the right on my screen is
> not terribly
> pleasing to my eyes (and can be rude for other developers).
>
> I was thinking of splitting it up like so:
> log.msg("Item wrote to MongoDB database %s/%s"
>    %(settings['MONGODB_DB'], settings['MONGODB_COLLECTION']),
>    level=log.DEBUG, spider=spider)
>
> Is this ok?  Are there any rules in Python when it comes to breaking up
> long lines of code?

For function calls, PEP8 suggests either an extra indent or line up as 
follows.
log.msg("Item wrote to MongoDB database %s/%s"
         %(settings['MONGODB_DB'], settings['MONGODB_COLLECTION']),
         level=log.DEBUG, spider=spider)

The point is to not look like a normal indent to clue reader that these 
are continuation lines and not new statements.

-- 
Terry Jan Reedy

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: n00b question on spacing Terry Reedy <tjreedy@udel.edu> - 2013-06-21 18:33 -0400

csiph-web