Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #63111 > unrolled thread
| Started by | Mark Lawrence <breamoreboy@yahoo.co.uk> |
|---|---|
| First post | 2014-01-04 05:38 +0000 |
| Last post | 2014-01-04 05:38 +0000 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: Strange behaviour with a for loop. Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-01-04 05:38 +0000
| From | Mark Lawrence <breamoreboy@yahoo.co.uk> |
|---|---|
| Date | 2014-01-04 05:38 +0000 |
| Subject | Re: Strange behaviour with a for loop. |
| Message-ID | <mailman.4891.1388813882.18130.python-list@python.org> |
On 04/01/2014 04:03, Sean Murphy wrote:
> 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
>
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 :)
--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.
Mark Lawrence
Back to top | Article view | comp.lang.python
csiph-web