It will be difficult to explain, but I'm trying to create a basic object to create other objects. The base class handles common tasks so that subclasses do not need to be implemented. However, I also need a static / class method that instantiates classes. So, for example, this is my base class:
class Base(object): def __init__(self, service, reference, vo=None): self.service = service self.reference = reference self.id = reference.getId() self.name = reference.getName()
The get_objects () method will take a list of identification numbers of records stored in the database, then get all these objects and make objects from them with one shot, and not hit the database for each identifier. The problem I am facing is that I have to use Base () in this method to instantiate the class. But this creates an instance of the Base class, not a subclass:
class Something(Base): def __init__(self, service, reference, vo=None): Base.__init__(self, service, reference, vo) do_extra_stuff()
My problem: I do not know if I can do this:
Something.get_objects(service, references)
Will it just run the Base init () method, or will it subclass the init () method (and the do_extra_stuff () method)?
source share