global or not global?

Justin Sheehy dworkin at
Fri May 26 16:54:25 EDT 2000

"Ralf Claus" <ralf.claus at> writes:

> class any():
>      def what():
>      def this():
>      def unknown():
> How can i define a variable, they could change in all this functions?
> And all functions must be read this variable!

Just an example, using your class and method names:

class any:
    def __init__(self):
        self.spam = 0
    def what(self):
        print self.spam
    def this(self):
        self.spam = self.spam + 1
    def unknown(self):
        self.spam = 0

To understand the use of 'self' there, read the standard Python
documentation, especially the sections on classes.  The tutorial is a
good place to start.



More information about the Python-list mailing list