Re: a simple 'for' question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • John McMonagle

    Re: a simple 'for' question

    Ben Keshet wrote:
    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')
    ...
    >
    Use os.path.join


    import os
    folders = ['1A2B', '1A6W', '56Y7']
    for x in folders:
    f = open(os.path.jo in('my/path/way', x, 'my_file.txt'), 'r')


Working...