Thread: Syntax question

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    6
    Rep Power
    0

    Syntax question


    print sixHundred.gradeReport()
    print gradeReport(sixHundred)


    I am confused as to why first line works
    and second line does not

    sixHundred is an instance of a user defined class
    gradeReport is a method of the class

    I am now using canopy and get the following error message for the second line

    NameError: name 'gradeReport' is not defined
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    194
    Rep Power
    2
    You still need to specify the class.

    Given the basic class:
    Code:
    class MyClass(object):
        def some_method(self):
            print("I'm some method.")
    You can call in these two different ways:
    Code:
    >>> a = MyClass()
    >>> a.some_method()
    I'm some method.
    >>> MyClass.some_method(a)
    I'm some method.
    >>>
    Of course in general practice the second is not generally used (there are a couple exceptions).

    -Mek
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    6
    Rep Power
    0
    [QUOTE=Mekire]You still need to specify the class.

    Thanks again Mek

    Another errata in the book I am SLOWLY working my way thru.

    Simon

IMN logo majestic logo threadwatch logo seochat tools logo