[Tutor] open multiple files

Alan Gauld alan.gauld at btinternet.com
Thu Aug 16 01:33:34 CEST 2007


"Paulo Quaglio" <paulo_quaglio at yahoo.com> wrote 

>  I'm beginning to learn how to program in python. 
> I need to process several text files simultaneously. 

Do you really mean simultaneously or just all in the same 
execution of the program? ie The one program run opens 
each file in sequence and reports the total?.

> The program needs to open several files (like a corpus) 
> and output the total number of words. 

OK, That sounds straightforward.

> I can do that with just one file but not the whole directory. 
> I tried glob but it didn't work. 

glob usually works so I assume you mean that you didn't 
get it to do what you wanted? Recall that glob returns a list 
of filenames. You need to iterate over that list processing 
each file in turn.

Can you show us a nbbit more of how you tried it? 
The code should be short enough that you can post it 
here on the list. Also post any error messages (the 
whole message not a summary).

HTH,

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld



More information about the Tutor mailing list