Classes and keywords

Michael Husmann Michael.Husmann at t-online.de
Mon Sep 18 14:51:34 EDT 2000


The following code is refused by python and I wonder why:

import sys

class Foo:
    def __init__(self):
        self.k = 0

    def set(self, w=self.k):
        return w * w


def main():
    k = Foo()
    print k.set(9)

if __name__ == "__main__": main()

Traceback (most recent call last):
  File "<stdin>", line 11, in ?
  File "<stdin>", line 15, in Foo
NameError: There is no variable named 'self'


Is there someone who can help me using such a keyword argument like I
have done in that 'set' function.



More information about the Python-list mailing list