Message31551
If you don't want the intere file on your memory, there's two solutions:
----------
import urllib
urlobj = urllib.urlopen("someurl")
header = urlobj.read(1)
# some other operations (no other urlobj.read())
contents = header + urlobj.read()
----------
I don't think it's a --good-- solution, because some other programmers can do other read() operations and mess all the result.
The other solution is:
----------
def readall(x) :
url = x.geturl
x.close()
try :
y = urllib.openurl(url)
except :
return None
return y.read()
import urllib
urlobj = urllib.urlopen("someurl")
header = urlobj.read(1)
# some other operations
contents = readall(urlobj)
----------
This is still a bad solution (two calls to the server for the same file).
On the contrary I'm pretty sure using a sequencial access this can be done without doing these workarounds.
(anyway I don't understand a thing: HTTP can't delegate the server to seek() the file?) |
|
Date |
User |
Action |
Args |
2007-08-23 14:52:32 | admin | link | issue1682241 messages |
2007-08-23 14:52:32 | admin | create | |
|