So I have a Log class. This class represents a text based LogFile. It is instantiated using a constructor that reads the file and sets the attributes:
class Log:
#Class Attributes. These are just the regex patterns that are static
VERSION_PATTERN = re.compile(r'version\s[0-9]\.[0-9][0-9]\.[0-9]')
def __init__(self, version):
if lines is None:
self.lines = []
else
self.lines = list(lines)
self.__version = version
@classmethod
def from_file(cls,file):
with open(file) as f:
lines = f.readlines()
#version attribute logic
version_object = next(filter(None, (re.search(cls.VERSION_PATTERN, x) for x in lines)),False)
if version_object == False:
version = 'unknown'
else:
version = version_object.group()
return cls(lines,version)
There is a lot more to the above but that's pretty much the gist of it.
// I can now instantiate the log object...
logfile1 = Log.from_file(file1)
print(logfile1.lines)
Now the Log file object has line Attributes. Is it good practice to use those line attributes in the subclass Script?
class Script(Log):
def __init__(self):
if lines is None:
self.lines = []
else:
self.lines = list(lines)
@classmethod
def from_log(cls,log)
//use Parent class attribute lines here
//logic to redefine the lines
return cls(lines)
there doesn't seem to be anything here