global or not global?

Justin Sheehy dworkin at ccs.neu.edu
Fri May 26 22:54:25 CEST 2000


"Ralf Claus" <ralf.claus at t-online.de> 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.

-Justin

 




More information about the Python-list mailing list