Ethan Furman <ethan@stonelea f.uswrote:
More than that, the brackets are CAUSING this problem. The "%" formatting
operator expects to find either a single item, or a tuple containing
multiple items. It does NOT look for a generic iterator. In this case,
the %s will use the whole list as its parameter. Python converts the list
to string, and the string representation of that one-item list is ['1'].
Just like that.
Right.
--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.
>Ben Keshet wrote:
>
>The form of slash ('\' vs '/') is irrelevant to Python. At least on
>Windows.
>
^- brackets not needed
>it didn't help. it reads the pathway "as is" (see errors for both
>tries). It looks like it had the write pathway the first time, but
>could not find it because it searched in the path/way instead of in the
>path\way. thanks for trying.
>tries). It looks like it had the write pathway the first time, but
>could not find it because it searched in the path/way instead of in the
>path\way. thanks for trying.
>The form of slash ('\' vs '/') is irrelevant to Python. At least on
>Windows.
>
>folders= ['1','2','3']
>for x in folders:
> print x # print the current folder
> filename='Folde r/%s/myfile.txt' %[x]
>for x in folders:
> print x # print the current folder
> filename='Folde r/%s/myfile.txt' %[x]
operator expects to find either a single item, or a tuple containing
multiple items. It does NOT look for a generic iterator. In this case,
the %s will use the whole list as its parameter. Python converts the list
to string, and the string representation of that one-item list is ['1'].
> f=open(filename ,'r')
>>
>gives: IOError: [Errno 2] No such file or directory:
>"Folder/['1']/myfile.txt"
>>
>gives: IOError: [Errno 2] No such file or directory:
>"Folder/['1']/myfile.txt"
>As far as the Python question of string substitution, "%s" % var is an
>appropriate way.
>appropriate way.
--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.
Comment