subclass of object

J

Jason Friedman

Hi, what is the difference between:

def MyClass(object):
pass

and

def MyClass():
pass
 
A

Alf P. Steinbach

* Jason Friedman:
Hi, what is the difference between:

def MyClass(object):
pass

and

def MyClass():
pass

If you really meant 'def', then the first is a routine taking one argument, and
the second is a routine of no arguments.

If you meant 'class' instead of 'def', then it depends on the Python version.

In Py2 the first then defines a new-style class, while the second defines an
old-style class. E.g. you can see some difference by checking with 'isinstance'.
In Py3 there's no difference.


Cheers & hth.,

- Alf
 
S

Steve Holden

Alf said:
* Jason Friedman:

If you really meant 'def', then the first is a routine taking one
argument, and the second is a routine of no arguments.

If you meant 'class' instead of 'def', then it depends on the Python
version.

In Py2 the first then defines a new-style class, while the second
defines an old-style class. E.g. you can see some difference by checking
with 'isinstance'. In Py3 there's no difference.
Interesting. I actually read "class" for "def" and replied accordingly.

As can plainly be seen ...

regards
Steve
 
A

Alf P. Steinbach

* Steve Holden:
Interesting. I actually read "class" for "def" and replied accordingly.

As can plainly be seen ...

Yes, the names act as comments about intent.

Such comments can be misleading about what the code actually does.

Since I think you're very interested in the human aspect of this I suggest you
try to find information about how master chess players remember chess boards. As
I recall, they find it really difficult to remember random boards, while boards
that represent actual chess games are remembered at a glance. Indicating that
what's remembered is at a much higher level of abstraction than piece positions.


Cheers,

- Alf
 
E

Ethan Furman

Steve said:
Interesting. I actually read "class" for "def" and replied accordingly.

Funny, so did I.

I'm sure it had something to do with the subject line. ;)

~Ethan~
 

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
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top