473,388 Members | 1,346 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.

a simple 'for' question

Hi fans,

I want to use a 'for' iteration to manipulate files in a set of folders,
something like:

folders= ['1A28','1A6W','56Y7']
for x in folders:
print x # print the current folder
f = open('my/path/way/x/my_file.txt', 'r')
...

where 'x' in the pathway should iterate over '1A28','1A6W','56Y7'. How
should I identify 'x' in the pathway line as the same x that is
iterating over 'folders'?

I am getting the following error:

Traceback (most recent call last):
File
"C:\Python25\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py" ,
line 310, in RunScript
exec codeObject in __main__.__dict__
File "C:\Linux\Dock_method_validation\myscripts\test_fo r.py", line 5,
in <module>
f = open('c:/Linux/Dock_method_validation/x/receptor.mol2', 'r')
IOError: [Errno 2] No such file or directory:
'c:/Linux/Dock_method_validation/x/receptor.mol2'

I tired several variations: %x, 'x', "x", etc. all gave me similar errors.

Thanks for your help,
BK
Jul 9 '08 #1
1 858
On Jul 9, 2:08 am, Ben Keshet <kesh...@umbc.eduwrote:
Hi fans,

I want to use a 'for' iteration to manipulate files in a set of folders,
something like:

folders= ['1A28','1A6W','56Y7']
for x in folders:
print x # print the current folder
f = open('my/path/way/x/my_file.txt', 'r')
...

where 'x' in the pathway should iterate over '1A28','1A6W','56Y7'. How
should I identify 'x' in the pathway line as the same x that is
iterating over 'folders'?

I am getting the following error:

Traceback (most recent call last):
File
"C:\Python25\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py" ,
line 310, in RunScript
exec codeObject in __main__.__dict__
File "C:\Linux\Dock_method_validation\myscripts\test_fo r.py", line 5,
in <module>
f = open('c:/Linux/Dock_method_validation/x/receptor.mol2', 'r')
IOError: [Errno 2] No such file or directory:
'c:/Linux/Dock_method_validation/x/receptor.mol2'

I tired several variations: %x, 'x', "x", etc. all gave me similar errors.

Thanks for your help,
BK
>>folders = ["a", "b", "c"]
for item in folders:
print item
file = open("my/path/way/" + item + "/my_file.txt", "r")
Jul 9 '08 #2

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

Similar topics

2
by: Trimbitas Sorin | last post by:
Hello I have a simple syntax question : What does the following line mean: 1: %checkType; ?? I know that @test="" is an array and $test="" is a simple variable. Thank you With best regards...
2
by: Raskolnikow | last post by:
Hi! I have a very simple problem with itoa() or the localtime(...). Sorry, if it is too simple, I don't have a proper example. Please have a look at the comments. struct tm *systime; time_t...
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...
2
by: Allain Bøge | last post by:
It is really a simple question. Visual Basic .NET (2003) I create 2 forms (Form1 and Form2) I create a checkbox in Form1 (checkbox1) I create a checkbox in Form2 (checkbox1) I go to Form1...
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);
3
by: Chrism2671 | last post by:
I'm new to XSLT/XML and I have a very simple, quick question. i've been trying to convert simple xml files into CSV files and have made a simple XSLT template using the w3 tutorials, but it doesn't...
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
10
by: Phillip Taylor | last post by:
Hi guys, I'm looking to develop a simple web service in VB.NET but I'm having some trivial issues. In Visual Studio I create a web services project and change the asmx.vb file to this: Imports...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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.