file operation question
Robin Munn
rmunn at pobox.com
Wed Oct 16 21:00:30 EDT 2002
In article <MPG.18177ff854c37806989680 at news3.attglobal.net>, Ivan Brkanac wrote:
> Hello I am making little application and in it I am processing some
> files
> and I decided to make code that rebuilds(fetch from Internet) file if it
> is not existing. But I get error message belov is part off the code and
> report off error. Problem is as I can see that win don't update file so
> fast and when script try to read file again it reads emptyy file. I used
> file.close() before opening file again for parsing. Is there any way to
> wait until file is closed so that it can be read again
>
> Regards Ivan
>
>
>
> try:
> self.inicijalizacija(open('./tecaji.dat','r'))
> except IOError:
> wxSetCursor(wxHOURGLASS_CURSOR) # Kursor U hourglas
> import urllib, urllister, urlparse
> f =urllib.URLopener().open(adresa)
> t = f.read() # UÀitamo je u string
> f.close()
> parser = urllister.URLLister()
> parser.feed(t)
> parser.close()
> t = open('./tecaji.dat','w')
> f = urllib.URLopener().open(urlparse.urljoin(adresa ,
> parser.urls[0]))
> t.write(f.read())
Ah. Here's your problem:
> t.close
> f.close # close file
These two lines should be:
t.close()
f.close() # close file
[snip the rest of the code]
With the (), you're calling the function. Without the (), you're just
referencing the function, which doesn't actually do anything. So the
tecaji.dat file was not actually getting closed.
I hope this helps.
--
Robin Munn
rmunn at pobox.com
More information about the Python-list
mailing list