Created
April 10, 2019 01:42
-
-
Save tnibert/4a0d205161c3768e2d09746f98defa94 to your computer and use it in GitHub Desktop.
Truncate n bytes from end of file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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