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


Groups > comp.lang.python > #7565

Re: split long string in two code lines

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!xlned.com!feeder5.xlned.com!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <python.list@tim.thechases.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'folks': 0.04; 'string,': 0.05; 'subject:two': 0.07; 'python': 0.08; '+0200,': 0.09; '>>>>': 0.09; 'long"': 0.09; 'subject:string': 0.09; 'pm,': 0.10; 'def': 0.12; 'wrote:': 0.14; '-tkc': 0.16; 'consecutive': 0.16; 'from:addr:python.list': 0.16; 'from:addr:tim.thechases.com': 0.16; 'from:name:tim chase': 0.16; 'literals': 0.16; 'message- id:@tim.thechases.com': 0.16; 'occasionally': 0.16; 'subject:lines': 0.16; 'subject:split': 0.16; 'text:': 0.16; 'cc:addr:python-list': 0.17; 'mon,': 0.17; 'header:In-Reply-To:1': 0.21; 'cc:no real name:2**0': 0.23; 'reason,': 0.23; 'subject:code': 0.23; '"this': 0.25; 'string': 0.26; "i'm": 0.27; 'closing': 0.28; '(as': 0.29; 'cc:addr:python.org': 0.30; '"but': 0.30; 'separate': 0.31; 'print': 0.31; 'tend': 0.32; 'list': 0.33; 'things': 0.33; '...': 0.34; 'there': 0.35; 'header:User-Agent:1': 0.35; 'changes.': 0.35; 'here,': 0.35; 'cc:2**1': 0.35; 'pretty': 0.37; 'put': 0.37; 'but': 0.38; 'though': 0.38; 'subject:: ': 0.38; 'some': 0.38; 'received:209': 0.39; 'huge': 0.62; 'noise': 0.67; 'truth': 0.68; '("this': 0.84; 'paren': 0.84; 'subject:long': 0.93
Date Mon, 13 Jun 2011 17:33:35 -0500
From Tim Chase <python.list@tim.thechases.com>
User-Agent Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.17) Gecko/20110414 Thunderbird/3.1.10
MIME-Version 1.0
To Tycho Andersen <tycho@tycho.ws>
Subject Re: split long string in two code lines
References <4df681ae$0$2694$4fafbaef@reader1.news.tin.it> <20110613215510.GP2322@point.cs.wisc.edu>
In-Reply-To <20110613215510.GP2322@point.cs.wisc.edu>
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-AntiAbuse This header was added to track abuse, please include it with any abuse report
X-AntiAbuse Primary Hostname - boston.accountservergroup.com
X-AntiAbuse Original Domain - python.org
X-AntiAbuse Originator/Caller UID/GID - [47 12] / [47 12]
X-AntiAbuse Sender Address Domain - tim.thechases.com
X-Source
X-Source-Args
X-Source-Dir
Cc python-list@python.org, Tracubik <affdfsdfdsfsd@b.com>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
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.199.1308004430.11593.python-list@python.org> (permalink)
Lines 44
NNTP-Posting-Host 82.94.164.166
X-Trace 1308004430 news.xs4all.nl 49038 [::ffff:82.94.164.166]:54222
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:7565

Show key headers only | View raw


On 06/13/2011 04:55 PM, Tycho Andersen wrote:
> On Mon, Jun 13, 2011 at 11:31:29PM +0200, Tracubik wrote:
>> 4            print "this is a very long string that i'm going to
>> write 5 here, it'll be for sure longer than 80 columns"
>>
>> Is there a better way to split the string?
>
> There is! Python (as C) concatenates string literals with nothing in
> between them.
>
>>>> def foo():
> ...     print "this is not such a huge line " \
> ...           "but it's still pretty long"
> ...
>>>> foo()
> this is not such a huge line but it's still pretty long

Python also treats consecutive strings as a single string, so you 
can do things like

   print ("this is not "
     "such a huge line "
     "even though it has "
     "lots of text in it."
     )

I tend to put the closing paren on its own line just to minimize 
noise in my VCS diffs when the text changes.  Truth be told, I 
often put the opening paren separate from the text:

   print (
     "this is not "
     "such a huge line "
     "even though it has "
     "lots of text in it."
     )

for the same reason, even though I know some folks on the list 
occasionally grouse about dangling-parens.

-tkc


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


Thread

split long string in two code lines Tracubik <affdfsdfdsfsd@b.com> - 2011-06-13 23:31 +0200
  Re: split long string in two code lines darnold <darnold992000@yahoo.com> - 2011-06-13 14:51 -0700
    Re: split long string in two code lines Terry Reedy <tjreedy@udel.edu> - 2011-06-13 23:55 -0400
  Re: split long string in two code lines Tycho Andersen <tycho@tycho.ws> - 2011-06-13 16:55 -0500
  Re: split long string in two code lines Redcat <redcat@catfolks.net> - 2011-06-13 22:21 +0000
  Re: split long string in two code lines Tim Chase <python.list@tim.thechases.com> - 2011-06-13 17:33 -0500
  Re: split long string in two code lines Chris Angelico <rosuav@gmail.com> - 2011-06-14 08:38 +1000
  Re: split long string in two code lines Tim Chase <python.list@tim.thechases.com> - 2011-06-13 18:03 -0500
  Re: split long string in two code lines Chris Angelico <rosuav@gmail.com> - 2011-06-14 09:11 +1000

csiph-web