[Tutor] Creating instance of child classes dynamically
Alan Gauld
alan.gauld at yahoo.co.uk
Sun Feb 7 09:58:32 EST 2021
On 07/02/2021 13:22, Sachit Murarka wrote:
> I have different classes in different python files. There are child classes
> and I do have a base class in a different class.
I'm not sure what that last bit means? "A base class in a different
class" Do you mean you have created the base class inside some other
class? That's extremely unusual, is there a reason? Or do you just mean
you have a seperate base class?
> My input to the python will be a string , according to the string I have to
> create an object of child class and call the functions.
Presumably you mean call the methods, not functions?
But otherwise that's fairly straightforward, you can
test your string and create whichever type of object
is required. Presumably there is something in the
string that lets you decide which class you need?
> Here I have to use the concept of reflection + dynamic polymorphism.
In python all polymorphism is dynamic.
And I'm not sure why you would need reflection.
I don't see anything in your problem that looks
like a candidate.
> Could anyone please help me here?
You probably need to be more specific.
May be give is two input samples and tell us which class
you need for each, and how you decided that. Once
see see a few examples we can help find a
programmable solution.
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos
More information about the Tutor
mailing list