T
T H
I’m new to python, sorry if my question is a bit naive, I was
wondering if it is possible to parse some text (ie. from a text file
or say html) and then dynamically create a class?
for example lets say the contents of the text file is:
functionName: bark arg1: numberBarks
functionName: run arg1: howFast arg2: howLong
and then from the text dynamically create a class like the one below
(including the functions and its implementation)
class Dog:
def bark(self, numberBarks, myArg):
print(‘numberBarks: ‘ + numberBarks)
print(‘myArg’ + myArg)
return
def run(self, howFast, howLong, myArg):
print(‘howFast: ‘ + howFast)
print(‘howLong’ + howLong)
print(‘myArg’ + myArg)
return
I know my question is a bit far fetched. Anyhow if it is possible how
is it done?
Thanks so much for any help!
wondering if it is possible to parse some text (ie. from a text file
or say html) and then dynamically create a class?
for example lets say the contents of the text file is:
functionName: bark arg1: numberBarks
functionName: run arg1: howFast arg2: howLong
and then from the text dynamically create a class like the one below
(including the functions and its implementation)
class Dog:
def bark(self, numberBarks, myArg):
print(‘numberBarks: ‘ + numberBarks)
print(‘myArg’ + myArg)
return
def run(self, howFast, howLong, myArg):
print(‘howFast: ‘ + howFast)
print(‘howLong’ + howLong)
print(‘myArg’ + myArg)
return
I know my question is a bit far fetched. Anyhow if it is possible how
is it done?
Thanks so much for any help!