Created
February 11, 2024 18:42
-
-
Save vladimirgamalyan/f9ad70622e79c1cbda358509042e6fc8 to your computer and use it in GitHub Desktop.
Python file read/write sample
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
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