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


Groups > comp.lang.python > #48886

Re: n00b question on spacing

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!eweka.nl!lightspeed.eweka.nl!194.109.133.81.MISMATCH!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <yoursurrogategod@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'python.': 0.02; 'parameters': 0.04; '21,': 0.07; 'string': 0.09; '%s"': 0.09; 'friday,': 0.09; 'notes:': 0.09; 'skip:% 20': 0.09; 'undefined': 0.09; 'subject:question': 0.10; 'cc:addr:python-list': 0.11; 'python': 0.11; 'wrote': 0.14; '*from:': 0.16; '*subject:': 0.16; '*to:': 0.16; 'code?': 0.16; 'concatenate': 0.16; 'length,': 0.16; 'pep8': 0.16; 'spacing': 0.16; 'splitting': 0.16; 'terribly': 0.16; 'url:pep-0008': 0.16; 'url:peps': 0.16; 'appropriate': 0.16; 'wrote:': 0.18; 'written': 0.21; '(the': 0.22; 'settings': 0.22; 'email addr:gmail.com&gt;': 0.22; 'rules': 0.22; 'cc:addr:python.org': 0.22; 'questions:': 0.24; 'url:dev': 0.24; 'question': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; 'this:': 0.26; 'code:': 0.26; 'header:In-Reply-To:1': 0.27; 'message-id:@mail.gmail.com': 0.30; 'url:mailman': 0.30; 'code': 0.31; 'lines': 0.31; 'breaking': 0.31; 'concern': 0.31; 'ray': 0.31; 'skip:- 30': 0.32; 'text': 0.33; 'url:python': 0.33; 'becomes': 0.33; 'fri,': 0.33; 'style': 0.33; 'screen': 0.34; 'basic': 0.35; 'skip:s 30': 0.35; 'something': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'really': 0.36; 'url:listinfo': 0.36; 'thanks': 0.36; "i'll": 0.36; 'hi,': 0.36; 'url:org': 0.36; 'example,': 0.37; 'so,': 0.37; 'two': 0.37; 'email addr:python.org': 0.37; 'level': 0.37; 'fact': 0.38; 'pm,': 0.38; 'little': 0.38; 'subject:': 0.39; '\xa0\xa0\xa0': 0.39; 'url:mail': 0.40; 'read': 0.60; 'break': 0.61; 'matter': 0.61; 'personal': 0.63; 'more': 0.64; 'email name:python-list': 0.65; 'within': 0.65; 'reply': 0.66; 'eyes': 0.78; 'everything.': 0.84; 'ok?': 0.84; '\xa0\xa0\xa0\xa0\xa0': 0.84; '2013': 0.98
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=fTQPWXkiO0xR+DwK+xa6OrYdbHFfkXgxw42SH7qHfSo=; b=po6eUtkpEhIO1N3Q/lcjEWUWRKkz/7ppVznBmOVZ7rqsOv8/bn8jw4XAW7G87+exR5 lv9mRVp9uzfCr3LIaV+jkiDJOFwYBt37ydx5KwPvE6S5VvI09+iap01NIvC5OJMWeesM iN6yeQ5Wyui8100TlD6DP8sJ3othIjNGktFOME7Lw7cMctxvDx7wak1b7TC1P4BBXeHA t7mfUqRKytxe30xV0ewXegF34g6uzJ5azNnB6oow+J3xFuz2o28q2YnLQjFqCqxi52ie q5n4D76EdPfftFeNcVoBAFRpBwi9u5aO3LWEeRHKx3/0XEKS32YaceWQfTcU3MR/seHx KXEg==
MIME-Version 1.0
X-Received by 10.180.108.129 with SMTP id hk1mr105979wib.42.1371852058580; Fri, 21 Jun 2013 15:00:58 -0700 (PDT)
In-Reply-To <24094189.2779.1371851333304.JavaMail.rgacote@ip-225.appropriatesolutions.com>
References <CAJ=2b07ETuSuo2+3Xu6vMOJA+q1JwUFTezO3LaYLG8wXd+FLBQ@mail.gmail.com> <24094189.2779.1371851333304.JavaMail.rgacote@ip-225.appropriatesolutions.com>
Date Fri, 21 Jun 2013 18:00:58 -0400
Subject Re: n00b question on spacing
From "Yves S. Garret" <yoursurrogategod@gmail.com>
To Ray Cote <rgacote@appropriatesolutions.com>
Content-Type multipart/alternative; boundary=e89a8f3bb04fa2de4304dfb132b4
Cc python-list@python.org
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.3671.1371852066.3114.python-list@python.org> (permalink)
Lines 177
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1371852066 news.xs4all.nl 15979 [2001:888:2000:d::a6]:42627
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:48886

Show key headers only | View raw


[Multipart message — attachments visible in raw view] - view raw

On Fri, Jun 21, 2013 at 5:48 PM, Ray Cote
<rgacote@appropriatesolutions.com>wrote:

>
> ------------------------------
>
> *From: *"Yves S. Garret" <yoursurrogategod@gmail.com>
> *To: *python-list@python.org
> *Sent: *Friday, June 21, 2013 5:17:28 PM
> *Subject: *n00b question on spacing
>
>
> 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?
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>
> Hi Yves:
> PEP8 is your definitive guide for style questions:
>   <http://www.python.org/dev/peps/pep-0008/>
>
> and this is an interesting set of notes:
>   <
> http://stackoverflow.com/questions/5931297/how-would-you-properly-break-this-line-to-match-pep8-rules
> >
>
>
> Basic rule is to break within parenthesis -- after that it becomes a
> matter of personal taste/style.
>
> In your specific example, I would do something like:
> log.msg(
>     "Item wrote to MongoDB database %s %s" % (
>
> settings['MONGODB_DB'],
> settings['MONGODB_COLLECTION]),
> level=log.DEBUG,
> spider=spider)
>
> Though you might want to:
> a) start your string right after the log.msg(
> b) put more than one settings on the same line
> c) put the last two parameters on the same line.
>
> I find that once I start breaking up lines for length, that I prefer to
> break up everything.
>
> Also remember when entering long lines of text that strings concatenate
> within parenthesis.
> So,
> ("a, b, c"
> "d, e, f"
> "g, h, i")
>
> Is the same as ("a, b, cd, e, fg, h, i")
>
> --Ray
>
> --
> Ray Cote, President
> Appropriate Solutions, Inc.
> We Build Software
> 603.924.6079
>

Thanks for your reply Ray.  My concern was that if I were to break with
something like this:
      log.msg("Item written to MongoDB database %s/%s"
    %(settings['MONGODB_DB'], settings['MONGODB_COLLECTION']),
    level = log.DEBUG, spider = spider)

I would get some undefined behaviour (the % is a little before the log.msg).

I'll read the links that you provided in order to learn more.

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


Thread

Re: n00b question on spacing "Yves S. Garret" <yoursurrogategod@gmail.com> - 2013-06-21 18:00 -0400

csiph-web