[spam][crazy][wrong] Genius Chatbot

Undiscussed Horrific Abuse, One Victim of Many gmkarl at gmail.com
Thu Mar 10 06:22:38 PST 2022


# draft of file-backed list
# like everything, it needs to be refactored to use list and database
abstractions

import os
class FileBackedList:
    def __init__(self, filename):
        try:
            self.file = open(filename, 'x+t')
        except FileExistsError:
            self.file = open(filename, 'r+t')
        self.offsets = []
        while True:
            self.offsets.append(self.file.tell())
            if self.file.readline() == '':
                break
    def __getitem__(self, offset):
        self.file.seek(self.offsets[offset])
        return self.file.readline()[:-1]
    def append(self, line):
        self.file.seek(0, os.SEEK_END)
        endpos = self.file.tell()
        self.file.write(line + '\n')
        self.offsets.append(endpos)
    def __iadd__(self, other):
        assert type(other) is str
        return self.append(other)
    def __del__(self):
        self.file.close()

# maybe it is not ok. it is a draft and has many errors.


More information about the cypherpunks mailing list