Truncate beginning of a file

Ben Finney bignose+hates-spam at benfinney.id.au
Mon May 5 01:16:43 EDT 2008


s0suk3 at gmail.com writes:

> file.truncate(X) will truncate the file to at most X bytes (i.e.
> leave the first X bytes of the file and throw away the rest).

Yes, by (IIRC) asking the filesystem to do this in a simple operation.
Most (all?) filesystems support this operation either directly or with
little effort.

> Is there a way to throw away, say, the first X bytes of the file,
> and leave the rest? (Without opening the same file for reading,
> reading and processing, overwriting the file with the new processed
> data, etc.)

I don't know of any filesystem that supports this operation without
reading the file data. The built-in 'file' type doesn't support it.

-- 
 \       "It's easy to play any musical instrument: all you have to do |
  `\       is touch the right key at the right time and the instrument |
_o__)                     will play itself."  -- Johann Sebastian Bach |
Ben Finney



More information about the Python-list mailing list