Created
July 16, 2017 09:00
-
-
Save mindforger/0776881a757bd43f7867ab5f6e690b5a to your computer and use it in GitHub Desktop.
python seek and write
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
import random | |
print("opening file") | |
maxlines = 50 | |
file = open("test.txt","a+") | |
file.seek(0,0) | |
ind_str = file.readline() | |
indicator = int(ind_str) | |
file.seek(len(ind_str)+indicator) | |
line = "%6d\n" % (random.randint(0,0xFFFF)) | |
file.seek(0,0) | |
line = "%6d\n" % (indicator+len(ind_str)+8) | |
file.write(line) | |
print("closing file") | |
file.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment