[Python-Dev] Draft proposal: Implicit self in Python 3.0 (original) (raw)
Fabien Schwob skink at evhr.net
Fri Jan 6 13:10:41 CET 2006
- Previous message: [Python-Dev] Draft proposal: Implicit self in Python 3.0
- Next message: [Python-Dev] Draft proposal: Implicit self in Python 3.0
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Example 1 (Python 2.x):
class Foo: def __init__(self, x): # 1: Explicit 'self' argument self.x = x # 2: 'self' must be used explicitly def bar(self, a, b): # 3: There are three arguments... print self.x + a + b Foo(10).bar(20, 30) # ...but only two explicit parameters # is presented
This document proposes to change this, as the next example shows:
Example 2 (Python 3.0):
class Foo: def __init__(x): # 1: Implicit self .x = x # 2: Brief form of: self.x = x def bar(a, b): # 3: Two arguments... print .x + a + b Foo(10).bar(20, 30) # ...and exactly two parameters
In my case, I think that the problem of self is mainly in the method definition. It's a little "hard" to understand why you have to use myFunction(self, otherArgs) when you create a class method. But the use of self in the code of the method is a good thing because it allow you to clearly say that you are working on a class property. In my case, I would like to have the following syntax in Python 3.0 :
class Foo: def init(x): self.x = x def bar(a, b): print self.x + a + b
My 0.2€ ;)
-- Fabien SCHWOB
- Previous message: [Python-Dev] Draft proposal: Implicit self in Python 3.0
- Next message: [Python-Dev] Draft proposal: Implicit self in Python 3.0
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]