Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mindforger/0776881a757bd43f7867ab5f6e690b5a to your computer and use it in GitHub Desktop.
Save mindforger/0776881a757bd43f7867ab5f6e690b5a to your computer and use it in GitHub Desktop.
python seek and write
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