473,396 Members | 2,102 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Re: Find class of an instance?

Am Mittwoch, den 06.08.2008, 08:44 -0400 schrieb Neal Becker:
Sounds simple, but how, given an instance, do I find the class?
<inst>.__class__

For example:

Python 2.5.2 (r252:60911, Aug 5 2008, 03:26:50)
[GCC 4.3.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>x = "hello"
x.__class__
<type 'str'>
>>>
--- Heiko.

Aug 6 '08 #1
2 1108
Heiko Wundram a écrit :
Am Mittwoch, den 06.08.2008, 08:44 -0400 schrieb Neal Becker:
>Sounds simple, but how, given an instance, do I find the class?

<inst>.__class__
Works for new-style classes only. The "generic" way to go is to use
type(obj).

<op>
Note that in both cases, what you'll get back is the class object, not
the class name
</op>
Aug 6 '08 #2
On 6 août, 15:52, Bruno Desthuilliers <bruno.
42.desthuilli...@websiteburo.invalidwrote:
Heiko Wundram a écrit :
Am Mittwoch, den 06.08.2008, 08:44 -0400 schrieb Neal Becker:
Sounds simple, but how, given an instance, do I find the class?
<inst>.__class__

Works for new-style classes only. The "generic" way to go is to use
type(obj).

<op>
Note that in both cases, what you'll get back is the class object, not
the class name
</op>
My.... I should shut up and check my facts :( Please everybody ignore
this brain fart.
Aug 6 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: a s i l b a . p t | last post by:
Can someone please explain why the following code raises error 2450?... Note: frmTest is a simple form with code behind form so it can be instantiated through the form's class module. Public...
3
by: Poewood | last post by:
Okay here are four classes for a pocket pc program: Input, fpositional, ComboBoxArray and TextBoxArray. The "input" class is the form. I use the fpositional class to handle most of the functions...
2
by: Andrzej Kaczmarczyk | last post by:
Hi How to find out in templated class if a type is implementing an interface. In particular I want to find out whether the type passed is a INullableValue I came up with somethig like this:...
3
by: POL8985 | last post by:
The application is developed in ASP.Net with a SQL Server database. Essentially, the application uses a single shared Connection object for all users logged into the system. The connection...
5
by: Mike Labosh | last post by:
In VB 6, the Form_QueryUnload event had an UnloadMode parameter that let me find out *why* a form is unloading, and then conditionally cancel the event. In VB.NET, the Closing event passes a...
23
by: thebjorn | last post by:
For the purpose of finding someone's age I was looking for a way to find how the difference in years between two dates, so I could do something like: age = (date.today() - born).year but that...
5
by: jm.suresh | last post by:
Hi I have three objects, all of them are instances of classes derived from a base class. Now, given one of the instance, I want to find the closest relative of the other two. How can I do this? ...
3
by: srinivasan srinivas | last post by:
Hi, I have written a class which has some attributes. I want to know how do i find out the size of an instance of this class?? class T(object):     def __init__(self, fn_name, *args, **kwds):    ...
3
by: raylopez99 | last post by:
I suspect the answer to this question is that it's impossible, but how do I make the below code work, at the point where it breaks (marked below). See error CS0411 This is the complete code. ...
3
by: jimgardener | last post by:
hi, i am a python newbie..while trying out some message passing between two object instances i came across a problem moduleA.py -------------------- import moduleB class MyClassA: def...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.