[Tutor] What is missing?
Remco Gerlich
scarblac@pino.selwerd.nl
Mon, 4 Feb 2002 15:09:43 +0100
On 0, Grimmtooth <grimmtoothtoo@yahoo.com> wrote:
>
> > DIR = "D:\\dp_test"
> > for filename in os.listdir(DIR):
> > full_path = os.path.join(DIR, filename)
> > myFile = open(full_path, 'r')
> > inFile = open('dp_hr.txt', 'w')
> > count = len(myFile.readlines())
> > print filename + ",", count
> > inFile.write(filename + ', ' + string(count))
>
> Where are you closing the files?
Closing them may look good and make your program a little more robust, but
isn't usually necessary in Python. The moment that inFile refers to a new
open file, the old file object is destroyed, and closed. That also happens
when the programs finishes.
--
Remco Gerlich