Easy question on opening a file
sean.berry2 at cox.net
Tue Sep 14 06:00:14 CEST 2004
"news.west.cox.net" <sean.berry2 at cox.net> wrote in message
news:3_t1d.296421$Oi.201894 at fed1read04...
>I want to check a directory, see if there are any files in it... then open
>each one and do something.
> I have this...
> files = os.listdir('/direcory')
> if len(files) > 0:
> for file in files:
> f1 = file(file, "r")
> do some other stuff
Figured out my mistake already.... 2 minutes later.
I should not be using the word file, which is a python keyword.
> But this raises a TypeError:
> TypeError: 'str' object is not callable
> So I tried replacing the line f1 = file(file, "r") with f1 = file('%s'
> %file, "r")
> But that does not work either.
> I know this is easy, anyone care to point out the solution.
> Sean Berry ~ Internet Systems Programmer
> BuildingOnline Inc.
> The Building Industry's Web Design and Marketing Agency
> Celebrating our 9th year in business, founded Aug. 1995
> Ph: 888-496-6648 ~ Fax: 949-496-0036
> --> Web Design Agency site: http://www.BuildingOnline.net
> --> Building Industry Portal: http://www.BuildingOnline.com
> --> Building Industry News: http://www.BuildingOnline.com/news/
> --> Home Plans: http://www.eHomePlans.com
More information about the Python-list