Class variables / global variables / Init variables 
Author Message
 Class variables / global variables / Init variables

Greetings all,

        I have a piece of code in which some variables are considered as
init variables ( something like the width of the windows in the gui, ...).

So far I am using constructions of the form :

class myClass :
        myVariable = 10

        def __init__(self):
                global myVariable

                newWindow = myWindow(myVariable) # Here I call

I wonder wether there is a better to achieve the same goal (class
variables or othere means)

Thanks all
_____________________________________________________________

                                        LaBoufarikoise



Fri, 01 Nov 2002 03:00:00 GMT  
 Class variables / global variables / Init variables

 >  class myClass :
 >      myVariable = 10
 >      def __init__(self):
 >              global myVariable
 >              newWindow = myWindow(myVariable)

This should not work at all, unless you have a global myVariable,
i.e. outside myClass.

If you want myVariable to be shared between all instances of myClass,
then I think you want this:

class myClass :
    myVariable = 10
    def __init__(self):
        newWindow = myWindow(myClass.myVariable)

If instead you want each instance of myClass to have its own myVariable,
then I think you want this:

class myClass :
    def __init__(self):
        self.myVariable = 10
        newWindow = myWindow(self.myVariable)

Then again, I could have completely misunderstood you.

/Mikael

-----------------------------------------------------------------------

WWW:     http://www.dtr.isy.liu.se/dtr/staff/mikael
Phone:   +46 - (0)13 - 28 1343
Telefax: +46 - (0)13 - 28 1339
Date:    15-May-00
Time:    17:27:46

This message was sent by XF-Mail.
-----------------------------------------------------------------------



Fri, 01 Nov 2002 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Global Variable / Sessions / ASP Application type Variable

2. Scope of global variable in class

3. SWIG, C++, classes, and adding them to the global variables

4. J and variable variables

5. awk variables --> shell variables

6. Variable "Variables"

7. concatenate two variables in a variable

8. Processing variable length/variable data files

9. variable contents to variable name

10. Variable Variables???

11. local variable and local variable in block behave differently

12. Variable variables in Ruby?

 

 
Powered by phpBB® Forum Software