Quantcast
Viewing all articles
Browse latest Browse all 1234

Python • Updating imported variable-values between modules

Hi!

I´ll try to explain this question through a example.

Well start with three modules, Sensor_Module, Calculate_Module and Master_Module.

In Calculate_Module we have a number of sensors measuring temp, humidity and other environmental values.

Theese values are imported to Calculate_Module

Code:

import Calculated Moduleimport importlib
and updated (if the importlib.reload actually updates the values) through

Code:

importlib.reload(Sensor_Module)
in functions using the values and needs updated values.

The results from Calculate_Module is then imported to Master_Module through

Code:

import Calculate_Moduleimport importlib
I have a function in Calculate_Module that updates the variables imported:

Code:

Def Update_Environmental_Variables()Temp1=Sensor_Module.Sensor1.Temperatureand a number of other sensors

But when i import the values from Calculate_Module into the Master_Module the values are not updated.
I have searched for guides about how to do this but sofar i have not found anything.

I have tried to test with

Code:

print(values from Sensor_Module)print(values from Calculate_Module)
And the Sensor_Module values are updated every cycle but the Calculate_Module-Values are not.


So to sum it up - I would like to import values from Sensor_Module into Calculate_Module and have them updated every cycle.
importlib.reload(Sensor_Module) in functions in Calculate_Module does not do the trick (theese functions are called from Master_Module if this could be the problem.


Does anyone know how to do this in a relative simple way (if there is one)?

I´m new to python so there could be an easy answer.

Best,

Martin

Statistics: Posted by Martin1234567 — Sun Jan 07, 2024 5:27 pm



Viewing all articles
Browse latest Browse all 1234

Trending Articles