Skip to content

Instantly share code, notes, and snippets.

@vladimirgamalyan
Created February 11, 2024 18:42
Show Gist options
  • Save vladimirgamalyan/f9ad70622e79c1cbda358509042e6fc8 to your computer and use it in GitHub Desktop.
Save vladimirgamalyan/f9ad70622e79c1cbda358509042e6fc8 to your computer and use it in GitHub Desktop.
Python file read/write sample
with open(file_name, mode='r+b') as f:
f.seek(-200, 2) # seek from the end
d = f.read(200) # read from current pos
f.seek(0) # seek to begin
f.write(d) # write to current pos
f.seek(-200, 2) # seek from the end
f.truncate() # truncate at current pos
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment