subclass of object

Discussion in 'Python' started by Jason Friedman, Apr 2, 2010.

  1. Hi, what is the difference between:

    def MyClass(object):
    pass

    and

    def MyClass():
    pass
     
    Jason Friedman, Apr 2, 2010
    #1
    1. Advertising

  2. * 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
     
    Alf P. Steinbach, Apr 2, 2010
    #2
    1. Advertising

  3. Jason Friedman

    Steve Holden Guest

    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/
     
    Steve Holden, Apr 2, 2010
    #3
  4. * 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
     
    Alf P. Steinbach, Apr 2, 2010
    #4
  5. Jason Friedman

    Ethan Furman Guest

    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~
     
    Ethan Furman, Apr 2, 2010
    #5
    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. jstorta
    Replies:
    3
    Views:
    476
    jstorta
    Feb 20, 2006
  2. Richard Lionheart
    Replies:
    27
    Views:
    440
    Jean-Hugues ROBERT
    May 4, 2004
  3. S.Volkov
    Replies:
    2
    Views:
    242
    S.Volkov
    Mar 12, 2006
  4. Trans
    Replies:
    8
    Views:
    352
    Robert Klemme
    Oct 23, 2008
  5. Fab

    Subclass of subclass

    Fab, Aug 9, 2012, in forum: C++
    Replies:
    0
    Views:
    417
Loading...

Share This Page