Python child class method with additional arguments [closed]
I have several tasks that are performed stepwise that share several arguments. Some later tasks require additional arguments. I have a parent class that reads in a set of files from a zip dir, appends to a single frame, performs some manipulation and outputs that file to directory. I have a second class that will then read in a second file, perform conditional manipulations with the additional arguments and the frame passed from the parent class. Firstly, Im new to inheritance and class method construction and want to modulate a series of tasks. I'd like to understand if it's even possible to pass arguments from a parent class to several child classes while still allowing additional arguments to be defined in each child class and their associated constructor statements. import pandas as pd class parent(): def __init__(self, arg1, arg2, arg3, arg4, frame1 = pd.Dataframe): self.location1 = arg1 self.file1 = arg2 self.func1 = (arg3 + arg4) def run(self): name = '\\' + self.location1 + '\\' + self.file1 + '.csv' frame1 = pd.read_csv(name, engine='python', header=None, sep='\\s+', skiprows=1, skipfooter=1) frame1 = self.frame1 = frame1 class child(parent): def __init__(self, func1, frame1, arg5, arg6, arg7, arg8): super(child, self).__init__(func1, frame1) self.location2 = arg5 self.file2 = arg6 self.func2 = (arg7 + arg8) def run(self): name = '\\' + self.location2 + '\\' + self.file2 + '.csv' frame2 = pd.read_csv(name, engine='python', header=None, sep='\\s+', skiprows=1, skipfooter=1) frame2 = self.frame2 = frame2 def result(self): child.run() Firstly, can a child class inherit the arguments from parent and as well as additional arguments? Secondly, how would I write the second statement below to pass 'file1' the instance of parent class and add arg5, arg6, arg7 and arg8. Is there a way to rewrite the "child.result" statement with correct syntax? Constructor statements: file1 = parent(arg1, arg2, arg3, arg4) parent.run(file1) child.result(file1,arg5, arg6, arg7, arg8)
![Python child class method with additional arguments [closed]](https://cdn.sstatic.net/Sites/softwareengineering/Img/apple-touch-icon@2.png?v=1ef7363febba)
I have several tasks that are performed stepwise that share several arguments. Some later tasks require additional arguments.
I have a parent class that reads in a set of files from a zip dir, appends to a single frame, performs some manipulation and outputs that file to directory. I have a second class that will then read in a second file, perform conditional manipulations with the additional arguments and the frame passed from the parent class.
Firstly, Im new to inheritance and class method construction and want to modulate a series of tasks. I'd like to understand if it's even possible to pass arguments from a parent class to several child classes while still allowing additional arguments to be defined in each child class and their associated constructor statements.
import pandas as pd
class parent():
def __init__(self, arg1, arg2, arg3, arg4, frame1 = pd.Dataframe):
self.location1 = arg1
self.file1 = arg2
self.func1 = (arg3 + arg4)
def run(self):
name = '\\' + self.location1 + '\\' + self.file1 + '.csv'
frame1 = pd.read_csv(name, engine='python', header=None, sep='\\s+', skiprows=1, skipfooter=1)
frame1 =
self.frame1 = frame1
class child(parent):
def __init__(self, func1, frame1, arg5, arg6, arg7, arg8):
super(child, self).__init__(func1, frame1)
self.location2 = arg5
self.file2 = arg6
self.func2 = (arg7 + arg8)
def run(self):
name = '\\' + self.location2 + '\\' + self.file2 + '.csv'
frame2 = pd.read_csv(name, engine='python', header=None, sep='\\s+', skiprows=1, skipfooter=1)
frame2 =
self.frame2 = frame2
def result(self):
child.run()
Firstly, can a child class inherit the arguments from parent and as well as additional arguments?
Secondly, how would I write the second statement below to pass 'file1' the instance of parent class and add arg5, arg6, arg7 and arg8. Is there a way to rewrite the "child.result" statement with correct syntax?
Constructor statements:
file1 = parent(arg1, arg2, arg3, arg4)
parent.run(file1)
child.result(file1,arg5, arg6, arg7, arg8)