Newbie

Andreas Palsson did at algonet.se
Thu Nov 16 10:25:59 EST 2000


Hello.

My name is Andreas and I'm trying to learn Python.

I have successfully been able to output a JPG-picture from a CGI-script,
but I would like to modify the script a little to be more 'memory
efficient'.

Currently I load the whole picture and the prints it.
Like this:
###
print "Content-Type: image/jpeg"
print
f=open('myjpeg.jpg', 'rb')
buffer = f.read()
print buffer
f.close()
###

But if the picture is 8-10mb in size, it becomes quite hard on the server.
So instead I would like to have a loop in which I read 32k, then outputs
32k until I've reached the end of the file.

I can get the filesize using "seek()" and "tell()", but I have problems
understanding how the "for"-loop should look like.

Anyone please help or direct me to a example?

regards...
	Andreas






More information about the Python-list mailing list