From: Jason Friedman on
Hi, what is the difference between:

def MyClass(object):
pass

and

def MyClass():
pass
From: Alf P. Steinbach on
* 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
From: Steve Holden on
Jason Friedman wrote:
> Hi, what is the difference between:
>
> def MyClass(object):
> pass
>
> and
>
> def MyClass():
> pass

In Python 3, nothing. In Python 2, the former gets you a subclass of
object whereas the latter gets you an instance of <type 'classobj'>, for
compatibility with pre-2.2 versions.

For most practical purposes there is no difference, so it doesn't matter
until it matters, so to speak. Unless you are noticing unexpected
behavior in your programs you probably don't need to worry (though you
might want to use the first form to ensure better Python 3 compatibility).

regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/
Holden Web LLC http://www.holdenweb.com/
UPCOMING EVENTS: http://holdenweb.eventbrite.com/

From: Steve Holden on
Alf P. Steinbach wrote:
> * 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.
>
Interesting. I actually read "class" for "def" and replied accordingly.

As can plainly be seen ...

regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/
Holden Web LLC http://www.holdenweb.com/
UPCOMING EVENTS: http://holdenweb.eventbrite.com/

From: Alf P. Steinbach on
* Steve Holden:
> Alf P. Steinbach wrote:
>> * 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.
>>
> 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