Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > subclass of object

Reply
Thread Tools

subclass of object

 
 
Jason Friedman
Guest
Posts: n/a
 
      04-02-2010
Hi, what is the difference between:

def MyClass(object):
pass

and

def MyClass():
pass
 
Reply With Quote
 
 
 
 
Alf P. Steinbach
Guest
Posts: n/a
 
      04-02-2010
* 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
 
Reply With Quote
 
 
 
 
Steve Holden
Guest
Posts: n/a
 
      04-02-2010
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/

 
Reply With Quote
 
Alf P. Steinbach
Guest
Posts: n/a
 
      04-02-2010
* 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
 
Reply With Quote
 
Ethan Furman
Guest
Posts: n/a
 
      04-02-2010
Steve Holden wrote:
> 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.


Funny, so did I.

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

~Ethan~
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Subclass of subclass Fab C++ 0 08-09-2012 09:54 AM
subclass a class in the namespace of the that subclass Trans Ruby 8 10-23-2008 07:24 AM
String subclass method returns subclass - bug or feature? S.Volkov Ruby 2 03-12-2006 06:46 PM
subclass has a variable that is subclass of same superclass jstorta Java 3 02-20-2006 08:42 PM
Problem assigning an Array object to an Array-subclass object Richard Lionheart Ruby 27 05-04-2004 06:42 AM



Advertisments