473,388 Members | 1,220 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

Re: a simple 'for' question


On Wed, 2008-07-09 at 00:00 -0400, Ben Keshet wrote:
oops, my mistake, actually it didn't work...
when I tried:
for x in folders:
print x # print the current folder
filename='Folder/%s/myfile.txt' %x
f=open(filename,'r')

it says: IOError: [Errno 2] No such file or directory:
'Folder/1/myfile.txt'
I believe it's because x is the position marker what you want instead is
the contents of folders at x; therefore folders[x]

HTH,
Tim


--
Timothy Cook, MSc
Health Informatics Research & Development Services
LinkedIn Profile:http://www.linkedin.com/in/timothywaynecook
Skype ID == timothy.cook
************************************************** ************
*You may get my Public GPG key from popular keyservers or *
*from this link http://timothywayne.cook.googlepages.com/home*
************************************************** ************

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (GNU/Linux)

iD8DBQBIdJQO2TFRV0OoZwMRAqntAKDMHzg+debOI82g0+SRXC lOLUGVewCff29C
C44vb9ffPU1WW7/5R8udU7U=
=6FP3
-----END PGP SIGNATURE-----

Jul 9 '08 #1
1 2009
Tim Cook a écrit :
On Wed, 2008-07-09 at 00:00 -0400, Ben Keshet wrote:
>oops, my mistake, actually it didn't work...
when I tried:
for x in folders:
print x # print the current folder
filename='Folder/%s/myfile.txt' %x
f=open(filename,'r')

it says: IOError: [Errno 2] No such file or directory:
'Folder/1/myfile.txt'

I believe it's because x is the position marker what you want instead is
the contents of folders at x; therefore folders[x]
Nope. Python's for loops iterate over elements, not over indices. Here,
the following code:

folders= ['1A28','1A6W','56Y7']
for x in folders:
print x
filename='Folder/%s/myfile.txt' %x
print filename

yields:

1A28
Folder/1A28/myfile.txt
1A6W
Folder/1A6W/myfile.txt
56Y7
Folder/56Y7/myfile.txt

IOW: the problem is elsewhere.

Jul 9 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: abcd | last post by:
I am trying to set up client machine and investigatging which .net components are missing to run aspx page. I have a simple aspx page which just has "hello world" printed.... When I request...
4
by: dba_222 | last post by:
Dear Experts, Ok, I hate to ask such a seemingly dumb question, but I've already spent far too much time on this. More that I would care to admit. In Sql server, how do I simply change a...
14
by: Giancarlo Berenz | last post by:
Hi: Recently i write this code: class Simple { private: int value; public: int GiveMeARandom(void);
30
by: galiorenye | last post by:
Hi, Given this code: A** ppA = new A*; A *pA = NULL; for(int i = 0; i < 10; ++i) { pA = ppA; //do something with pA
17
by: Chris M. Thomasson | last post by:
I use the following technique in all of my C++ projects; here is the example code with error checking omitted for brevity: _________________________________________________________________ /*...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.