[Tutor] returning the entire line when regex matches

Alan Gauld alan.gauld at btinternet.com
Wed May 6 02:00:48 CEST 2009


"Nick Burgess" <burgess.nick at gmail.com> wrote

> for root, dirs, files in os.walk('./'):
>     for f in files:
>         if f.endswith('.txt'):
>             allfiles.append(os.path.join(root, f))
               myFunction( os.path.join(root,f) )

> This returns a list of the *.txt files. Of course now I am stuck on
> how to apply the delimiter and search function to the items in the
> list..?  

Either call your function on each file as you find it -- no need 
for a list, or...

for f in allfiles:
      myFunction(f)

Provided your function can take the filename as a parameter 
either method will work.

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



More information about the Tutor mailing list