class definition syntax

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • harryos

    class definition syntax

    hi
    i have seen some class definitions like

    class MyClass(object) :
    def __init__(self):
    ....

    what does the object keyword inside the braces in MyClass() mean?
    Has it got any significance?

    thanks in advance
    harry
  • Diez B. Roggisch

    #2
    Re: class definition syntax

    harryos wrote:
    hi
    i have seen some class definitions like
    >
    class MyClass(object) :
    def __init__(self):
    ....
    >
    what does the object keyword inside the braces in MyClass() mean?
    Has it got any significance?
    It indicates a so-called new-style-class. The new style classes have been
    available since python2.2:



    Diez

    Comment

    • Wojtek Walczak

      #3
      Re: class definition syntax

      On Fri, 29 Aug 2008 02:50:57 -0700 (PDT), harryos wrote:
      class MyClass(object) :
      def __init__(self):
      ....
      >
      what does the object keyword inside the braces in MyClass() mean?
      Has it got any significance?
      It's inheritance. MyClass class inherits from object class.
      Check out point 9.5 in the tutorial.

      --
      Regards,
      Wojtek Walczak,

      Comment

      • Ken Starks

        #4
        Re: class definition syntax

        harryos wrote:
        hi
        i have seen some class definitions like
        >
        class MyClass(object) :
        def __init__(self):
        ....
        >
        what does the object keyword inside the braces in MyClass() mean?
        Has it got any significance?
        >
        thanks in advance
        harry
        It is a syntax used for 'new type' classes, not so new any more.

        If you google that phrase, you get many references.

        Here is a tutorial dating back to 2005.
        Latest news coverage, email, free stock quotes, live scores and video are just the beginning. Discover more every day at Yahoo!



        Comment

        • Bruno Desthuilliers

          #5
          Re: class definition syntax

          harryos a écrit :
          hi
          i have seen some class definitions like
          >
          class MyClass(object) :
          def __init__(self):
          ....
          >
          what does the object keyword
          It's not a keyword.
          inside the braces in MyClass() mean?
          Answer is here:




          Has it got any significance?
          <ironic>
          Nope, why ? It just look better that way...
          </ironic>

          Harry, this neswgroup is - as you may have noticed by now - very newbie
          friendly. But this is not a reason for not reading *at least* the
          FineManual's tutorial.

          Comment

          Working...