Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #63107
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news2.arglkargh.de!news.albasani.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <mhysnq1964@icloud.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; 'python.': 0.02; 'parameters': 0.04; 'element': 0.07; 'modify': 0.07; 'sys': 0.07; 'filename': 0.09; 'filenames': 0.09; 'filenames:': 0.09; 'newly': 0.09; 'spelled': 0.09; 'question.': 0.14; '%s\\n"': 0.16; 'filename)': 0.16; 'received:mac.com': 0.16; 'referencing': 0.16; 'index': 0.16; 'all.': 0.16; 'bit': 0.19; 'result.': 0.19; 'slightly': 0.19; 'import': 0.22; 'to:name:python- list@python.org': 0.22; 'print': 0.22; 'sean': 0.24; 'script': 0.25; 'shown': 0.26; 'array': 0.29; 'character': 0.29; 'code': 0.31; 'getting': 0.31; 'os,': 0.31; 'languages': 0.32; 'subject:with': 0.35; 'something': 0.35; 'but': 0.35; 'charset:us- ascii': 0.36; 'received:17': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'results.': 0.60; 'providing': 0.61; 'different': 0.65; 'results': 0.69; 'wish': 0.70 |
| X-Proofpoint-Virus-Version | vendor=fsecure engine=2.50.10432:5.11.87,1.0.14,0.0.0000 definitions=2014-01-03_08:2014-01-03,2014-01-03,1970-01-01 signatures=0 |
| X-Proofpoint-Spam-Details | rule=notspam policy=default score=0 spamscore=0 suspectscore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=7.0.1-1308280000 definitions=main-1401030228 |
| From | Sean Murphy <mhysnq1964@icloud.com> |
| Content-type | text/plain; charset=us-ascii |
| Content-transfer-encoding | quoted-printable |
| Subject | Strange behaviour with a for loop. |
| Date | Sat, 04 Jan 2014 15:03:35 +1100 |
| To | "python-list@python.org" <python-list@python.org> |
| MIME-version | 1.0 (Mac OS X Mail 6.6 \(1510\)) |
| X-Mailer | Apple Mail (2.1510) |
| 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 | <https://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 | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.4887.1388811827.18130.python-list@python.org> (permalink) |
| Lines | 45 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1388811827 news.xs4all.nl 2866 [2001:888:2000:d::a6]:49651 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:63107 |
Show key headers only | View raw
Hello all.
This is a newly question. But I wish to understand why the below code is providing different results.
import os, sys
if len(sys.argv) > 2:
filenames = sys.argv[1:]
else
print ("no parameters provided\n")
sys.edit()
for filename in filenames:
print ("filename is: %s\n" %filename)
The above code will return results like:
filename is test.txt
If I modify the above script slightly as shown below, I get a completely different result.
if len(sys.argv) > 2:
filenames = sys.argv[1]
else
print ("no parameters provided\n")
sys.exit()
for filename in filenames:
print ("filename is: %s\n" % filename)
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.
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).
Sean
filename is: t
filename
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
Strange behaviour with a for loop. Sean Murphy <mhysnq1964@icloud.com> - 2014-01-04 15:03 +1100 Re: Strange behaviour with a for loop. Larry Hudson <orgnut@yahoo.com> - 2014-01-04 13:25 -0800
csiph-web