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 7584033
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T18:49:30+00:00 2026-05-30T18:49:30+00:00

To determine the class, I can do so: class A: pass a = A

  • 0

To determine the class, I can do so:

class A: pass    
a = A

type(A) is type #True

or:

import inspect
inspect.isclass(A) 

But how to determine the type of class instance, not knowing the class name?

Something like this:

isinstance(a, a.__class__.__name__)
#TypeError: isinstance() arg 2 must be a type or tuple of types

I found one solution, but it does not work with Python 3x

import types

class A: pass
a = A()

print(type(a) == types.InstanceType)
#AttributeError: 'module' object has no attribute 'InstanceType'

Solution:

if '__dict__' in dir(a) and type(a) is not type:
  • 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-05-30T18:49:31+00:00Added an answer on May 30, 2026 at 6:49 pm

    type(a) is the type of the instance, i.e., its class. a.__class__ is also a reference to the instance’s class, but you should use type(a).

    types.InstanceType is only for old-style classes in versions of Python pre-3.0, where all instances had the same type. You should be using new-style classes (derived from object) in 2.x. In Python 3.0, all classes are new-style classes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given a class instance, is it possible to determine if it implements a particular
I need to pass an instance variable (self.rank) to be used by a class
Within some library class, is there a way I can I determine which webpage
I'd like to be able to determine what class will be called given an
I need to determine if a Class object representing an interface extends another interface,
Is there any way to take a Class and determine if it represents a
Is there any non-hacky way to determine wether a class' superclass implements a particular
Goal: to programmatically determine the sizes (in bytes) of the fields of a class.
I have a class C(Of T). I want to determine if some given value
Is it possible in C++ to determine number of variables/fields in the generic class?

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.