I thought that I really understood how to reference a variable in a
different module, but it turns out that I don't. I'd appreciate a clue
stick appropriately applied.
In one module's (variablePage.py) __init__() method widgets are defined
and I assign variables to the displayed values of some of these. For
example:
self.UoDlow = self.vlowEnd.GetValue()
I want to display that value (self.UoDlow) in a widget in a different
module.
At the top of the recipient module, the defining module is imported,
from variablePage import modVar
and then I try to use the imported variable:
self.varUoDlow.SetValue(modVar().UoDlow)
but this produces a python error:
Traceback (most recent call last):
File "/data1/eikos/fuzSetPage.py", line 471, in OnAdd
self.varUoDlow.SetValue(modVar().UoDlow)
TypeError: __init__() takes exactly 3 arguments (1 given)
What are the two other arguments, and where do they belong?
Alternatively, if this is the incorrect approach to display the same values on
two different wxPython tabs, please point me toward how to do this properly.
Rich
···
--
Richard B. Shepard, Ph.D. | The Environmental Permitting
Applied Ecosystem Services, Inc. | Accelerators(TM)
<http://www.appl-ecosys.com> Voice: 503-667-4517 Fax: 503-667-8863
I thought that I really understood how to reference a variable in a
different module, but it turns out that I don't. I'd appreciate a clue
stick appropriately applied.
In one module's (variablePage.py) __init__() method widgets are defined
and I assign variables to the displayed values of some of these. For
example:
Modules don't have methods. What does self refer to in the code below?
self.UoDlow = self.vlowEnd.GetValue()
I want to display that value (self.UoDlow) in a widget in a different
module.
At the top of the recipient module, the defining module is imported,
from variablePage import modVar
and then I try to use the imported variable:
self.varUoDlow.SetValue(modVar().UoDlow)
And what does self refer to here?
but this produces a python error:
Traceback (most recent call last):
File "/data1/eikos/fuzSetPage.py", line 471, in OnAdd
self.varUoDlow.SetValue(modVar().UoDlow)
TypeError: __init__() takes exactly 3 arguments (1 given)
You need to rewrite that statement as multiple statements to try and get a handle on which expression is causing the problem. It's probably the call to modVar(), but how can we know?
What are the two other arguments, and where do they belong?
If it *is* the call to modVar() then you will find in your variablePage module that the modVar class's __init__() method has three arguments, the first of which will (should) be self. This first argument is provided by the interpreter because you are calling a method of a specific instance. Your code needs to supply the other two.
Since you wrote that code (I presume - I know *I* didn't I can't give you much help beyond this.
Alternatively, if this is the incorrect approach to display the same values on
two different wxPython tabs, please point me toward how to do this properly.
You do seem to need to understand namespaces a little better.
Modules don't have methods. What does self refer to in the code below?
The variable in the class where I want to assign the imported value.
You need to rewrite that statement as multiple statements to try and get a
handle on which expression is causing the problem. It's probably the call
to modVar(), but how can we know?
More research taught me what I did incorrectly, and what to do to get the
results I want. That is, rather than importing the entire class from the
source module, import only the variables I want to display.
Thanks, Steve,
Rich
···
On Thu, 27 Sep 2007, Steve Holden wrote:
--
Richard B. Shepard, Ph.D. | The Environmental Permitting
Applied Ecosystem Services, Inc. | Accelerators(TM)
<http://www.appl-ecosys.com> Voice: 503-667-4517 Fax: 503-667-8863
I must be misunderstanding something but this text sounds a little bit strange…
A variable in my view something that is changed or something that is computed as some other variable is changed
In both cases I suggest using an accessor to the variable… some kind of “model” that can be passed around and that holds the data you need.
From the module you import the SomeModel class that knows how to initialize itself based on a minimum of parameter that you provide to the constructor. You subsequently use this
I recently discovered Trellis and I’m quickly becoming a fan boy (think pompoms and "Give me a T! Give me an R!.. etc.)
More research taught me what I did incorrectly, and what to do to get the
results I want. That is, rather than importing the entire class from the
source module, import only the variables I want to display.