Re: Find class of an instance?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Heiko Wundram

    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.

  • Bruno Desthuilliers

    #2
    Re: Find class of an instance?

    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>

    Comment

    • bruno.desthuilliers@gmail.com

      #3
      Re: Find class of an instance?

      On 6 août, 15:52, Bruno Desthuilliers <bruno.
      42.desthuilli.. .@websiteburo.i nvalidwrote:
      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.


      Comment

      Working...