When to derive from object?

Discussion in 'Python' started by Igor Mikushkin, Oct 13, 2009.

  1. Hello all!

    I'm a newbie to Python.
    Could you please say me when it is better to derive from "object" and
    when not?

    Thanks,
    Igor
    Igor Mikushkin, Oct 13, 2009
    #1
    1. Advertising

  2. Igor Mikushkin a écrit :
    > Hello all!
    >
    > I'm a newbie to Python.


    Welcome onboard

    > Could you please say me when it is better to derive from "object" and
    > when not?


    - When not : when using Python >= 3.0, or when already subclassing
    another class.

    - When : any other case !-)
    Bruno Desthuilliers, Oct 13, 2009
    #2
    1. Advertising

  3. Igor Mikushkin

    Matimus Guest

    On Oct 13, 7:45 am, Igor Mikushkin <> wrote:
    > Hello all!
    >
    > I'm a newbie to Python.
    > Could you please say me when it is better to derive from "object" and
    > when not?
    >
    > Thanks,
    > Igor


    The only reason to derive from 'object' is if there is some sort of
    weird side effect of using new style classes. I _have_ run into some
    interesting scenarios when creating com objects in python using the
    win32com module. Other than that, I always use new style classes
    (derived from object).

    Here are some articles that point out the distinctions between old and
    new style classes: http://python.org/doc/newstyle/

    Matt
    Matimus, Oct 13, 2009
    #3
  4. Igor Mikushkin

    Matimus Guest

    On Oct 13, 8:02 am, Matimus <> wrote:
    > On Oct 13, 7:45 am, Igor Mikushkin <> wrote:
    >
    > > Hello all!

    >
    > > I'm a newbie to Python.
    > > Could you please say me when it is better to derive from "object" and
    > > when not?

    >
    > > Thanks,
    > > Igor

    >
    > The only reason to derive from 'object' is ...


    erm... that should say "the only reason _not_ to derive from object"
    oops.

    Matt
    Matimus, Oct 13, 2009
    #4
  5. Can someone point me to some reason on why not to derive from Object
    when using Python >= 3.0? I am a Python novice, I need some
    background.

    On Oct 13, 10:49 am, Bruno Desthuilliers <bruno.
    > wrote:
    > Igor Mikushkin a écrit :
    >
    > > Hello all!

    >
    > > I'm a newbie to Python.

    >
    > Welcome onboard
    >
    > > Could you please say me when it is better to derive from "object" and
    > > when not?

    >
    > - When not : when using Python >= 3.0, or when already subclassing
    > another class.
    >
    > - When : any other case !-)
    Anson Mackeracher, Oct 13, 2009
    #5
  6. On Tue, Oct 13, 2009 at 1:34 PM, Anson Mackeracher <> wrote:
    > Can someone point me to some reason on why not to derive from Object
    > when using Python >= 3.0? I am a Python novice, I need some
    > background.
    >


    It's redundant. Python 3 cleaned up a lot of the warts that appeared
    in Python over the years. Old-style classes (classes that didn't
    inherit from object) were one of them. Every class in Python 3 is
    derived from object whether you specify it or not.

    > On Oct 13, 10:49 am, Bruno Desthuilliers <bruno.
    > > wrote:
    >> Igor Mikushkin a écrit :
    >>
    >> > Hello all!

    >>
    >> > I'm a newbie to Python.

    >>
    >> Welcome onboard
    >>
    >> > Could you please say me when it is better to derive from "object" and
    >> > when not?

    >>
    >> - When not : when using Python >= 3.0, or when already subclassing
    >> another class.
    >>
    >> - When : any other case !-)

    >
    > --
    > http://mail.python.org/mailman/listinfo/python-list
    >
    Benjamin Kaplan, Oct 13, 2009
    #6
  7. Igor Mikushkin

    Paul Rudin Guest

    Benjamin Kaplan <> writes:

    >
    > It's redundant. Python 3 cleaned up a lot of the warts that appeared
    > in Python over the years. Old-style classes (classes that didn't
    > inherit from object) were one of them. Every class in Python 3 is
    > derived from object whether you specify it or not.


    .... it could be argued that having two ways to specify the same thing
    (derivation from object explictly or implicitly) is a wart in itself :/
    Paul Rudin, Oct 13, 2009
    #7
  8. Igor Mikushkin

    Terry Reedy Guest

    Paul Rudin wrote:
    > Benjamin Kaplan <> writes:
    >
    >> It's redundant. Python 3 cleaned up a lot of the warts that appeared
    >> in Python over the years. Old-style classes (classes that didn't
    >> inherit from object) were one of them. Every class in Python 3 is
    >> derived from object whether you specify it or not.

    >
    > ... it could be argued that having two ways to specify the same thing
    > (derivation from object explictly or implicitly) is a wart in itself :/


    Every function with default arguments can be called two or more ways.
    Every function that returns None can be written two or more ways.
    ;-)
    Terry Reedy, Oct 13, 2009
    #8
  9. Igor Mikushkin

    greg Guest

    Terry Reedy wrote:

    > Every function with default arguments can be called two or more ways.
    > Every function that returns None can be written two or more ways.


    And in general, anything of any sort with any kind of
    default can be written in two ways. Somehow I doubt that
    the ZoP was intended to discourage providing defaults!

    --
    Greg
    greg, Oct 14, 2009
    #9
    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. Amil
    Replies:
    1
    Views:
    366
    Teemu Keiski
    Nov 20, 2003
  2. Henke
    Replies:
    4
    Views:
    443
    Scott Allen
    Aug 13, 2004
  3. JC
    Replies:
    0
    Views:
    430
  4. Brian Takita
    Replies:
    5
    Views:
    686
    Brian Takita
    May 27, 2005
  5. Tinku
    Replies:
    3
    Views:
    1,172
    Alf P. Steinbach
    Jan 31, 2010
Loading...

Share This Page