Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!selfless.tophat.at!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: 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; 'newbie': 0.03; 'string.': 0.04; 'subject:two': 0.07; 'python': 0.08; '+0200,': 0.09; 'long"': 0.09; 'subject:string': 0.09; 'this:': 0.10; '>>>': 0.12; 'def': 0.12; 'received:209.85.214.174': 0.14; 'received:mail- iw0-f174.google.com': 0.14; 'wrote:': 0.14; '"copyright",': 0.16; '"credits"': 0.16; '"license"': 0.16; '[gcc': 0.16; 'indent': 0.16; 'linux2': 0.16; 'literals': 0.16; 'subject:lines': 0.16; 'subject:split': 0.16; 'cc:addr:python-list': 0.17; 'mon,': 0.17; 'header:In-Reply-To:1': 0.21; 'cc:2**0': 0.22; 'cc:no real name:2**0': 0.23; 'subject:code': 0.23; 'code': 0.24; '"this': 0.25; 'index': 0.25; 'string': 0.26; "i'm": 0.27; 'received:209.85.214': 0.28; '(as': 0.29; 'all,': 0.30; 'cc:addr:python.org': 0.30; '"but': 0.30; 'print': 0.31; "i've": 0.33; '...': 0.34; 'question': 0.34; 'there': 0.35; 'header:User- Agent:1': 0.35; 'here,': 0.35; 'charset:us-ascii': 0.36; 'received:google.com': 0.37; 'something': 0.37; 'received:209.85': 0.37; 'pretty': 0.37; 'received:128': 0.38; 'but': 0.38; 'subject:: ': 0.38; 'perhaps': 0.39; 'received:209': 0.39; 'really': 0.40; 'more': 0.60; 'huge': 0.62; 'here': 0.66; 'spaces': 0.73; 'subject:long': 0.93 Date: Mon, 13 Jun 2011 16:55:10 -0500 From: Tycho Andersen To: Tracubik Subject: Re: split long string in two code lines References: <4df681ae$0$2694$4fafbaef@reader1.news.tin.it> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4df681ae$0$2694$4fafbaef@reader1.news.tin.it> User-Agent: Mutt/1.5.21 (2010-09-15) Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 45 NNTP-Posting-Host: 82.94.164.166 X-Trace: 1308002119 news.xs4all.nl 49182 [::ffff:82.94.164.166]:51953 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:7563 On Mon, Jun 13, 2011 at 11:31:29PM +0200, Tracubik wrote: > Hi all, > > newbie question here > > how can i write code like this: > > 1 def foo(): > 2 for index in ... > 3 for plsdoit in ... > 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" > > > the only way i've found is to use the "/", but than i've to write > something like this: Perhaps you mean '\'? > > 1 def foo(): > 2 for index in ... > 3 for plsdoit in ... > 4 print "this is a very long string that i'm going to/ > 5 write here, it'll be for sure longer than 80 columns" > > what i don't really like is that line 5 is not indented. if i indent > it, the spaces will be counted as spaces of the string. > > Is there a better way to split the string? There is! Python (as C) concatenates string literals with nothing in between them. Python 2.6.2 (r262:71600, Jun 8 2009, 11:11:42) [GCC 4.3.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> 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 \t