Re: a simple 'for' question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Rajanikanth Jammalamadaka

    Re: a simple 'for' question

    Thanks for correcting my typo norseman.

    Ben: I forgot a slash after the first string as norseman pointed out.

    Raj

    On Tue, Jul 8, 2008 at 5:51 PM, norseman <norseman@hughe s.netwrote:
    >
    Almost correct: There is a typo. Should read:
    >
    for x in folders:
    open('my/path/way/'+x+'/myfile.txt','r' )
    >
    >
    >
    >
    Rajanikanth Jammalamadaka wrote:
    >>
    >Hi!
    >>
    >Try this
    >>
    >for x in folders:
    > open('my/path/way'+x+'myfile. txt','r')
    >>
    >Cheers,
    >>
    >Raj
    >>
    >On Tue, Jul 8, 2008 at 5:08 PM, Ben Keshet <keshet1@umbc.e duwrote:
    >>>
    >>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\python win\pywin\frame work\scriptutil s.py",
    >>line 310, in RunScript
    >> exec codeObject in __main__.__dict __
    >> File "C:\Linux\Dock_ method_validati on\myscripts\te st_for.py", line 5, in
    >><module>
    >> f = open('c:/Linux/Dock_method_val idation/x/receptor.mol2', 'r')
    >>IOError: [Errno 2] No such file or directory:
    >>'c:/Linux/Dock_method_val idation/x/receptor.mol2'
    >>>
    >>I tired several variations: %x, 'x', "x", etc. all gave me similar
    >>errors.
    >>>
    >>Thanks for your help,
    >>BK
    >>--
    >>http://mail.python.org/mailman/listinfo/python-list
    >>>
    >>
    >>
    >>
    >
    >


    --
    "For him who has conquered the mind, the mind is the best of friends;
    but for one who has failed to do so, his very mind will be the
    greatest enemy."

    Rajanikanth
Working...