base-class

how to get derived class name from base class

how to get derived class name from base class Question: I have a base class Person and derived classes Manager and Employee. Now, what I would like to know is the object created is Manager or the Employee. The person is given as belows: from Project.CMFCore.utils import getToolByName schema = getattr(Person, ‘schema’, Schema(())).copy() + Schema((TextField(‘FirstName’, …

Total answers: 7

Creating a singleton in Python

Creating a singleton in Python Question: This question is not for the discussion of whether or not the singleton design pattern is desirable, is an anti-pattern, or for any religious wars, but to discuss how this pattern is best implemented in Python in such a way that is most pythonic. In this instance I define …

Total answers: 38

Cast base class to derived class python (or more pythonic way of extending classes)

Cast base class to derived class python (or more pythonic way of extending classes) Question: I need to extend the Networkx python package and add a few methods to the Graph class for my particular need The way I thought about doing this is simplying deriving a new class say NewGraph, and adding the required …

Total answers: 9