Feb-04-2020, 06:04 AM
The ultimate answer to your question is OPP(Object Oriented Programming).
Make everything that goes together part of a Class, then you can refer to any part easily and make as many "instances" of the class as you want. You then refer to the instance and can run it's functions(methods) whenever you want, or you can hand the entire class to something else through "inheritance". I'm a newbie at this, but OOP is where it's at. The classes I use most are pygame sprites.
I can't really tell what you program does, but I made a rough example just to show the idea. If you make something like this work then you can read in a process as many different files as you want.
Make everything that goes together part of a Class, then you can refer to any part easily and make as many "instances" of the class as you want. You then refer to the instance and can run it's functions(methods) whenever you want, or you can hand the entire class to something else through "inheritance". I'm a newbie at this, but OOP is where it's at. The classes I use most are pygame sprites.
I can't really tell what you program does, but I made a rough example just to show the idea. If you make something like this work then you can read in a process as many different files as you want.
class Data_File(): def __init__(self, file_name): self.test_file = open(file_name, 'r') self.test_lines = test_file.readlines() self.test_file.close() self.liner = (self.test_lines[1]) self.colon = self.liner.find(":") self.semi = self.liner.find(";") self.comma = self.liner.find(",") self.length = len(self.liner) self.name = (self.liner[self.colon+1:self.semi]) self.location = (self.liner[self.semi+1:self.comma]) self.gps = (self.liner[self.comma+1:self.length]) def htmlwr(self): Tester = (self.location, "foo") print(Tester) dat1 = Data_file("Database1.txt") dat2 = Data_file("Database2.txt") dat1.htmlwr() dat2.htmlwr() print(dat1.liner, dat1.name) print(dat2.location, dat1.location) bunch_o_stuff = (dat1.gps, dat1.liner, dat2.length, dat1.name, dat2.liner, dat1.test_lines) print("Here is a bunch of stuff", bunch_o_stuff)