When to derive from object?

I

Igor Mikushkin

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
 
B

Bruno Desthuilliers

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 !-)
 
M

Matimus

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
 
A

Anson Mackeracher

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.
 
B

Benjamin Kaplan

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.
 
P

Paul Rudin

Benjamin Kaplan said:
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 :/
 
T

Terry Reedy

Paul said:
... 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.
;-)
 
G

greg

Terry said:
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!
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top