Skip to content

Instantly share code, notes, and snippets.

@tnibert
Created April 10, 2019 01:42
Show Gist options
  • Save tnibert/4a0d205161c3768e2d09746f98defa94 to your computer and use it in GitHub Desktop.
Save tnibert/4a0d205161c3768e2d09746f98defa94 to your computer and use it in GitHub Desktop.
Truncate n bytes from end of file
# truncate num_bytes off the end of a file
import os
def trunc(filename, num_bytes):
with open(filename, 'rb+') as fi:
fi.seek(-1 * num_bytes, os.SEEK_END)
fi.truncate()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment