-
-
Save mindforger/f137ee6d59dd1ebb68d2394619be54e7 to your computer and use it in GitHub Desktop.
python circular buffer log 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
import random | |
indicator = 0 | |
maxline = 30 | |
def readSeek(file_ptr): | |
file_ptr.seek(0,0) | |
ind_str = file.readline() | |
return int(ind_str) | |
def calcSeek(): | |
return (indicator*8) | |
def writeSeek(file_ptr, ind): | |
file_ptr.seek(0,0) | |
line = "%6d\n" % (ind) | |
file.write(line) | |
print("opening file") | |
file = open("test.txt","r+") | |
indicator = readSeek(file) | |
print(str(indicator)) | |
indicator += 1 | |
if indicator > maxline: | |
print("indicator overflow, wrappning around!") | |
indicator = 0 | |
else: | |
print(str(indicator)) | |
file.seek(calcSeek(),0) | |
line = "%6d\n" % (random.randint(0,0xFFFF)) | |
file.write(line) | |
writeSeek(file,indicator) | |
print("closing file") | |
file.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment