Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed2.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; 'python.': 0.02; 'parameters': 0.04; 'element': 0.07; 'modify': 0.07; 'sys': 0.07; 'character,': 0.09; 'chunk': 0.09; 'filename': 0.09; 'filenames': 0.09; 'filenames:': 0.09; 'lawrence': 0.09; 'newly': 0.09; 'spelled': 0.09; 'strings.': 0.09; 'typed': 0.09; 'wrong,': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'assume': 0.14; 'language.': 0.14; 'question.': 0.14; '%s\\n"': 0.16; '(list)': 0.16; '3.3,': 0.16; 'filename)': 0.16; 'referencing': 0.16; 'unlikely': 0.16; 'index': 0.16; ':-)': 0.16; 'all.': 0.16; 'language': 0.16; 'wrote:': 0.18; 'bit': 0.19; 'result.': 0.19; 'slightly': 0.19; 'memory': 0.22; 'example': 0.22; 'import': 0.22; 'cc:addr:python.org': 0.22; 'print': 0.22; 'load': 0.23; 'sean': 0.24; "shouldn't": 0.24; 'question': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; 'script': 0.25; 'shown': 0.26; 'header:In- Reply-To:1': 0.27; 'point': 0.28; 'testing': 0.29; 'feature': 0.29; 'array': 0.29; 'character': 0.29; "doesn't": 0.30; 'characters': 0.30; 'errors': 0.30; 'url:mailman': 0.30; 'code': 0.31; 'getting': 0.31; 'os,': 0.31; 'file': 0.32; 'languages': 0.32; 'option': 0.32; 'regular': 0.32; 'another': 0.32; 'text': 0.33; 'url:python': 0.33; "i'd": 0.34; 'subject:with': 0.35; 'basic': 0.35; 'something': 0.35; 'test': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'everyone.': 0.36; 'in.': 0.36; 'url:listinfo': 0.36; "didn't": 0.36; 'method': 0.36; 'useful': 0.36; 'charset:us-ascii': 0.36; 'thanks': 0.36; 'url:org': 0.36; 'positive': 0.37; 'being': 0.38; 'message-id:@gmail.com': 0.38; 'work?': 0.38; 'planning': 0.38; 'pm,': 0.38; 'rather': 0.38; 'anything': 0.39; 'either': 0.39; 'url:mail': 0.40; 'blank': 0.60; 'expression': 0.60; 'negative': 0.60; 'results.': 0.60; 'new': 0.61; 'providing': 0.61; 'first': 0.61; "you've": 0.63; 'header :Message-Id:1': 0.63; 'our': 0.64; 'provide': 0.64; 'different': 0.65; 'within': 0.65; 'anything.': 0.68; 'results': 0.69; 'wish': 0.70; 'cut': 0.74; '"".': 0.84; 'does?': 0.84; 'to:addr:yahoo.co.uk': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=content-type:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=AmaJX6MBih3i02aBZ4y9S8QPZqgwzRc5YXsv8V+k/ic=; b=KGWichc8ZnxG8Crcqsq64BRUeOYE5ftrwXrukVGwBWLQliJn215qBkJ6OMjCZ1OYjX mLlDlJh1xQmqaNPZIYVphxJ5erwv8h66N0JUJC0/cBo1dhka4HO0RnAV1zrV0DVb27R1 h8MQoFlshKudGmDTHvpBV2DtA8Zv05I6o9eFBuCyPeSJaGaT5jJvjOFRYWb2OprL15lT K9XiqsdZKUrLPR5Gp9mMDKOsPBWUPasdoAlSeNNUlAoDL+NcsMmbGztyCmn6prJxPATF jTu+0E6kdVeGLi90ZEphjMG/WFet5Pj+2mGPi4h5he3cFxdrcJTcY59YciqZ0WXQKLHv WyLA== X-Received: by 10.68.190.228 with SMTP id gt4mr101929036pbc.94.1388814887046; Fri, 03 Jan 2014 21:54:47 -0800 (PST) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 6.6 \(1510\)) Subject: Re: Strange behaviour with a for loop. From: Sean Murphy In-Reply-To: Date: Sat, 4 Jan 2014 16:54:42 +1100 Content-Transfer-Encoding: quoted-printable References: <4DC5A4FC-CCAF-446B-B41C-23E52C2389B6@icloud.com> To: Mark Lawrence X-Mailer: Apple Mail (2.1510) X-Mailman-Approved-At: Sat, 04 Jan 2014 08:31:07 +0100 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 123 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1388820668 news.xs4all.nl 2943 [2001:888:2000:d::a6]:60569 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:63116 Thanks everyone. Mark thanks for the correction on the ':'. Since I didn't cut and copy, = rather typed it out. Errors crept in. :-) another question in relation to slicing strings. If you want to get a = single character, just using the index position will get it. If I use = the following, shouldn't it also work? when I use Python 3.3, it didn't = provide anything. a =3D "test.txt" print a[3] result is: 't print a[3:1] Nothing is printed.=20 print a[3:2] Nothing is printed. print a[3:-1] t.tx is printed. Why doesn't the positive number of characters to be splice return = anything while the negative value does? sorry about these basic questions. I do like the splice feature within = Python. Also what is the best method of testing for a blank string? end of paragraph line 1=20 new paragraph of line 1. The above example text is what I want to test for. I am planning to = either load the whole file in as a single chunk of memory using = fp.read() or store it into an array by using fp.readlines(). The first = option I see being useful because you can create a regular expression to = test for multiple '\n'. While in an array (list) I would have to test = for a blank line which I assume would be "". Any suggestions on this would be welcomed. Sean=20 print a[ On 04/01/2014, at 4:38 PM, Mark Lawrence = wrote: > On 04/01/2014 04:03, Sean Murphy wrote: >> Hello all. >>=20 >> This is a newly question. But I wish to understand why the below code = is providing different results. >>=20 >> import os, sys >>=20 >>=20 >> if len(sys.argv) > 2: >> filenames =3D sys.argv[1:] >> else >> print ("no parameters provided\n") >> sys.edit() >>=20 >> for filename in filenames: >> print ("filename is: %s\n" %filename) >>=20 >> The above code will return results like: >>=20 >> filename is test.txt >>=20 >> If I modify the above script slightly as shown below, I get a = completely different result. >>=20 >> if len(sys.argv) > 2: >> filenames =3D sys.argv[1] >> else >> print ("no parameters provided\n") >> sys.exit() >>=20 >> for filename in filenames: >> print ("filename is: %s\n" % filename) >>=20 >> The result is the filename is spelled out a character at a time. The = bit I am missing is something to do with splicing or referencing in = Python. >>=20 >> Why am I getting different results? In other languages I would have = got the whole content of the element when using the index of the array = (list). >>=20 >>=20 >> Sean >> filename is: t >> filename >>=20 >=20 > As you've already had answers I'd like to point out that your test for = len(sys.argv) is wrong, else is missing a colon and sys.edit() is very = unlikely to work :) >=20 > --=20 > My fellow Pythonistas, ask not what our language can do for you, ask = what you can do for our language. >=20 > Mark Lawrence >=20 > --=20 > https://mail.python.org/mailman/listinfo/python-list