Sharing Variables Between Files



  • I'm not accustomed to having a boot.py and a main.py having one process run after another and trying to share variables between processes. The official Python documentation shows this is the appropriate way to do shared variables, but it doesn't seem to be the way it will work here. Can someone show an example or point out documentation that shows how this is done?



  • Well I haven't written much yet to share, but it doesn't make sense to me that the gpy device can assume that the mobile network is always available and with good signal strength. Also, boot.py appears to be where the network connection is established, but what if in the main.py I want to put the device to sleep for some duration and wake the mobile network connection under some conditions. I would need to refer to the mobile object declared in the boot.py hence the sharing variable need.

    This gpy unit will be traveling and the network signal strength drops off frequently because I live in a horrible rural area.. where networking life is miserable. I would assume the same idea of putting the device into sleep to save on juice would be applicable here, but if its declared in boot.py how would it be interacted with in main.py?



  • @Sn3akyP3t3 Please can you give more details on your project ? The Pycom modules are programmed with micropython which is a subset of Python. You can create classes in different files in flash and create an instance of them in the main.py. In the python classes you can create getters and setters for variables.


Log in to reply
 

Pycom on Twitter