[Tutor] Parsing data from a set of files iteratively

Alan Gauld alan.gauld at btinternet.com
Fri May 18 20:57:40 CEST 2012


On 18/05/12 19:23, Spyros Charonis wrote:
> Dear Python community,
>
> I have a set of ~500 files which I would like to run a script on.
 > ...Is there a way in which I can iteratively execute my script
 > over all 500 files

Yes.
You could use os.walk() or the glob module depending on whether
the files are in a folder heirarchy or a single folder.

That will give you access to each file.
Put your functionality into a function taking a single file
as input and a list to which you append the new data.
Call that function for each file in turn.

Try that and if you get stuck come back with a more specific question, 
the code you used and the full error text.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/



More information about the Tutor mailing list