How does the file.seek() work ?

gert gert.cuykens at gmail.com
Mon Aug 24 14:50:55 EDT 2009


I want the file pointer set to 100 and overwrite everything from there

curl -C 100 -T upload2.wsgi http://192.168.2.17/appwsgi/wsgi/upload2.wsgi
-v

w+ overwrites my file completely
r+ overwrites nothing
a+ only makes my file bigger

import os

def application(environ, response):
    query=os.path.join(os.path.dirname(__file__),'teeeeeeeeeemp')
    range=environ.get('HTTP_RANGE','bytes=0-').replace
('bytes=','').split(',')
    offset=[]
    for r in range: offset.append(r.split('-'))
    with open(query,'w+') as f:
         f.seek(int(offset[0][0]))
         while True:
             chunk=environ['wsgi.input'].read(8192).decode('latin1')
             if not chunk: break
             f.write(chunk)
    f=open(query)
    l=str(os.fstat(f.fileno()).st_size)
    response('200 OK', [('Content-Type', 'text/plain'), ('Content-
Length', str(len(l)))])
    return [l]

also why must I open the file a second time to know how big it is ?





More information about the Python-list mailing list