Using globals with classes

Diez B. Roggisch deets at web.de
Fri Aug 12 10:22:56 CEST 2005


> Is there a way to make a Python function "remember" the values of certain
> variables ? Or use fortran 95 like use module, only : varname, type of
> within a def ?

I'm not sure what you are trying to do here - but it seems to me that
you are not properly designing your application. You really shouldn't
use the Designers code-insertion features. The reason is simple: you
the have two tools to write code in instead of one (your editor/IDE).
And you don't make plotkey* global - use instance variables.

 So I'm going to describe how I dow work with PyQt:

- I create a Widget in the designer
- compile it using pyuic
- _extend_ it
- write my code in the extended version

So I end up with something like this (I use modules to separate
classes):

ui/plot.ui
ui/plot.py
views/plot.py

where views/plot.py looks like this:

class Plot(ui.plot.Plot):
    def __init__(self, *args):
         ui.plot.Plot.__init__(self, *args)
         self.plotkey1 = <whatever>

    def update(self):
         # access self.plotkey here
       


HTH,

DIez




More information about the Python-list mailing list