How to I do this in Python ?

random832 at fastmail.us random832 at fastmail.us
Fri Aug 16 14:17:04 EDT 2013


On Fri, Aug 16, 2013, at 7:47, Roy Smith wrote:
> There is no need to shell out to dd just to do this.  All dd is doing 
> for you is seeking to the offset you specify and closing the file.  You 
> can do that entirely in Python code.
> 
> http://docs.python.org/2.7/library/stdtypes.html#file.seek

*ahem*

http://docs.python.org/2.7/library/stdtypes.html#file.truncate

The dd recipe was written some time over a decade ago as the easiest way
to achieve this at a shell prompt (before the truncate tool was added to
coreutils), and no-one's ever thought twice about it.



More information about the Python-list mailing list