checking type of my own objects

Discussion in 'Python' started by Tobiah, Sep 14, 2003.

  1. Tobiah

    Tobiah Guest

    Hi,

    I have a module that defines a few classes.
    one of them is Event. If I do:

    e = Event()
    print type(e)

    I get back:

    <class 'score.Event'>

    now to check to see whether a given object
    is an Event or not, I could parse the string
    output of type, but that does not seem correct.

    What is the best way to check the type?

    Thanks,

    Tobiah
    Tobiah, Sep 14, 2003
    #1
    1. Advertising

  2. Tobiah wrote:

    > What is the best way to check the type?


    e.__class__ is Event

    or if you want to include subclasses:

    isinstance(e, Event)

    --
    Erik Max Francis && && http://www.alcyone.com/max/
    __ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE
    / \ If the sun comes up / And you're not home / I'll be strong
    \__/ India Arie
    Erik Max Francis, Sep 14, 2003
    #2
    1. Advertising

  3. Tobiah

    Tobiah Guest


    > e.__class__ is Event


    I appreciate that, thank you.

    Tobiah
    Tobiah, Sep 14, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Stefan Siegl
    Replies:
    1
    Views:
    771
  2. Saverio M.
    Replies:
    0
    Views:
    512
    Saverio M.
    Jul 3, 2006
  3. Gordon Airporte

    Type-checking unpickled objects

    Gordon Airporte, Nov 18, 2005, in forum: Python
    Replies:
    3
    Views:
    260
    Gordon Airporte
    Nov 21, 2005
  4. Tom Bradford
    Replies:
    4
    Views:
    624
    Florian Diesch
    Mar 10, 2006
  5. David Filmer
    Replies:
    17
    Views:
    259
    J. Romano
    Aug 18, 2004
Loading...

Share This Page