Kent Johnson <[EMAIL PROTECTED]> wrote in message news:<[EMAIL PROTECTED]>...
> John Aherne wrote:
> > Unfortunately, when it comes to delete, I get a permission error. And
> > yes, when I run the program and try to delete the file from the
> > command prompt, I get a permission error.
> > 
> > As far as I can tell, I assume the file is being kept open in the
> > DictReader call. But I can't work out how I can close the file -
> > .close comand also returns an error. I was assuming that on the return
> > from the call the file would be closed - mistakenly I now think.
>  
> >     locallist = [(x) for x in os.listdir(localdir) if   
> > os.path.getsize(os.path.join(localdir, x)) > 0]     # upload all local
> > files
> >     localfiles = fnmatch.filter(locallist, '*.OUT')
> >     for localname in localfiles:  
> >        localpath = os.path.join(localdir, localname) 
> >        if localname[-3:] == 'OUT':
> >             csv_file = file(localpath)
> >         reader = csv.DictReader(csv_file,['phone', 'msg', 'PZ', 'MP'])
> >         for row in reader:
> >             phone = row['phone']
> >                 msg = row['msg']
> > 
> >             print time.ctime(time.time()),' uploading', msg,  'to',
> > phone
> 
>              csv_file.close() # after you finish reading the rows
> 
> Kent

Thanks for the responses.

I had tried the csv_file.close() but was getting an exception in my
try/except block.

I reckon I'm doing this wrong or in the wrong place. So I'll try
reworking the code and see where I get.

At least I can forget about the DictReader class. It's my code I need
to look at.

Thanks

John
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to