By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,737 Members | 1,310 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,737 IT Pros & Developers. It's quick & easy.

Re: Find class of an instance?

P: n/a
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
Share this Question
Share on Google+
2 Replies

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.