1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Rep Power

    Newbie questoins :/

    i'm reading this code
    pykanoid game
    there is alot of
    self. ......
    there are classes too
    how does the self thing work in so many classes :/
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Rep Power
    'self' is just an explicit reference to the object in which 'self' is bound.

    Every member method in Python must include in its list of parameters as first formal parameter a name to which Python will bind a reference to the object. You could use the name 'this' or 'lolita' or any valid name, but by consensus, and by the word of GvR, the name 'self' is most often used.

    'self' is just like 'this' in Java, except for the fact that you explicitly include it as first of your formal parameters in any member method, whereas in Java, the parameter is there, and the reference is passed, but everything is implicit.

    For more information, look at Chapter 9. Classes in the Python Tutorial, or, for a more terse explanation, you could look at 4.21 What is self? in the Python FAQ.
    Last edited by percivall; September 3rd, 2003 at 06:41 AM.

IMN logo majestic logo threadwatch logo seochat tools logo