Mike Rovner wrote:
Right. Thanks for the correction.
Fredrik Lundh wrote:
Mike Rovner wrote:
if os.stat says the_file is too big:
fh = open(the_file, 'rb')
fh.seek(2008, 2)
should be
fh.seek(-2008, 2)
right?
data = fh.read()
fh.close()
assert len(data)==2008 # you may want some error pr
Right. Thanks for the correction.
Fredrik Lundh wrote:
Mike Rovner wrote:
if os.stat says the_file is too big:
fh = open(the_file, 'rb')
fh.seek(2008, 2)
should be
fh.seek(-2008, 2)
right?
data = fh.read()
fh.close()
assert len(data)==2008 # you may want some error processing here
fh =
Mike Rovner wrote:
> if os.stat says the_file is too big:
> fh = open(the_file, 'rb')
> fh.seek(2008, 2)
should be
fh.seek(-2008, 2)
right?
> data = fh.read()
> fh.close()
> assert len(data)==2008 # you may want some error processing here
> fh = open(the_file, 'wb')
> fh.writ
rbt wrote:
if os.stat says the file is too big:
read the file
trim = only keep the last 2008 bytes (This is where I get stuck)
write trim back out to the original file
Would someone demonstrate the *best* most efficient way of doing this?
if os.stat says the_file is too big:
fh = open
Hi guys,
I need to truncate a file from the top down. I imagine doing something
like this:
if os.stat says the file is too big:
read the file
trim = only keep the last 2008 bytes (This is where I get stuck)
write trim back out to the original file
Would someone demonstrate the *best*