473,385 Members | 1,341 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,385 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 2000
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: _________________________________________________________________ /*...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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...

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.