Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8207143
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T08:54:29+00:00 2026-06-07T08:54:29+00:00

I have a base class Person and derived classes Manager and Employee . Now,

  • 0

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', required = True, widget = StringWidget(label='First Name', i18n_domain='project')), TextField('Last Name', required = True, widget = StringWidget(label='Last Name', i18n_domain='i5', label_msgid='label_pub_city'))
class Manager(BaseContent):
  def get_name(self):
    catalog = getToolByName(self, "portal_catalog")
      people = catalog(portal_type='Person')
      person={}
      for object in people:
        fname = object.firstName
        lname = object.lastName
        person['name'] = fname+' '+ lname
        # if the derived class is Employee then i would like go to the method title of employee and if its a Manager then go to the title method of Manager
        person['post'] = Employee/Manager.title()
      return person

For Manager and employees they are like (employee is also similar but some different methods)

from Project.Person import Person
class Manager(Person):
    def title(self):
      return "Manager"

For Employee the title is ‘Employee’. When I create a Person it is either Manager or the Employee. When I get the person object the class is Person but I would like to know whether it is from the derived class ‘Manager’ or ‘Employee’.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T08:54:30+00:00Added an answer on June 7, 2026 at 8:54 am

    You can use x.__class__.__name__ to retrieve the class name as a string, e.g.

    class Person:
        pass
    
    class Manager(Person):
        pass
    
    class Employee(Person):
        pass
    
    def get_class_name(instance):
        return instance.__class__.__name__
    
    >>> m = Manager()
    >>> print get_class_name(m)
    Manager
    >>> print get_class_name(Employee())
    Employee
    

    Or, you could use isinstance to check for different types:

    >>> print isinstance(m, Person)
    True
    >>> print isinstance(m, Manager)
    True
    >>> print isinstance(m, Employee)
    False
    

    So you could do something like this:

    def handle_person(person):
        if isinstance(person, Manager):
            person.read_paper()     # method of Manager class only
        elif isinstance(person, Employee):
            person.work_hard()      # method of Employee class only
        elif isinstance(person, Person):
            person.blah()           # method of the base class
        else:
            print "Not a person"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an Object base class, and I have several derived classes called Item,
I have base class BaseClass and derived classes DerivedA , DerivedB , and DerivedC
If I have a Model like the following example class Person < ActiveRecord::Base has_many
I have a very simple object model with a base class Person and two
I have an abstract base class called Person with subclasses Employee and Customer. How
the question is simple. I have a base abstract class (person). From this i
I have the following models: class Person < ActiveRecord::Base has_many :accounts, :through => :account_holders
I have a model in my rails application which is class Person < ActiveRecord::Base
I have a base class like this: public class BaseResponse { public string ErrorMessage
I have a base class with many sub-classes, and a generic function to cache

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.