0

I have a file with size 1.5GB

if i use this code:

class Base:

    def __init__(self, base):
        try:
            print(f'{colorama.Fore.YELLOW}Открытые базы...')
            start = time.time()
            f = open(base, encoding = 'utf-8')
            self.base = set(f.read().split('\n'))
            end = time.time()

            print(f'{colorama.Fore.GREEN}Открытые базы составило {float(start - end)} секунд')
        except:
            self.base = []

    def in_base(self, adress):
        if adress in self.base:
            return True
        
        return False

after start i crashing my pc

kiran mathew
  • 130
  • 3
  • The likely problem is not speed, but memory. Python objects can impose a lot of memory overhead, and `.split` on a large string needs to make new objects, while the original is still temporarily in memory. Instead, ask Python to split the lines while it is reading in the file - see the linked duplicate for more information. For future reference, please read [ask] and [mre]. Clearly the problem is not with the class design, or with using `colorama` to print debug trace messages. – Karl Knechtel Jun 04 '22 at 11:12

0 Answers0