Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #48887 > unrolled thread
| Started by | Gary Herron <gherron@digipen.edu> |
|---|---|
| First post | 2013-06-21 15:26 -0700 |
| Last post | 2013-06-21 15:26 -0700 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: n00b question on spacing Gary Herron <gherron@digipen.edu> - 2013-06-21 15:26 -0700
| From | Gary Herron <gherron@digipen.edu> |
|---|---|
| Date | 2013-06-21 15:26 -0700 |
| Subject | Re: n00b question on spacing |
| Message-ID | <mailman.3672.1371853574.3114.python-list@python.org> |
On 06/21/2013 02: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?
>
>
This is how I'd do it: (And it's *FAR* clearer -- You win no points for
clarity by having it all in one statement.)
fmt = "Item wrote to MongoDB database %s/%s"
msg = fmt % (settings['MONGODB_DB'],
settings['MONGODB_COLLECTION'])
log.msg(msg, level=log.DEBUG, spider=spider)
Gary Herron
--
Dr. Gary Herron
Department of Computer Science
DigiPen Institute of Technology
(425) 895-4418
Back to top | Article view | comp.lang.python
csiph-web