I've written a python application which can be set in development or production mode by using an environment variable. This variable can be passed as a CLI argument:
if len(argv) >= 2:
environ['DISCOVERY_ENV'] = argv[1]
else:
environ['DISCOVERY_ENV'] = 'development'
The problem now is that this environment is not being set. Which means if I've following code, it doesn't work:
if environ.get('DISCOVERY_ENV') == 'production':
import adafruit_ads1x15.ads1015 as ADS
from adafruit_ads1x15.analog_in import AnalogIn
import busio
import board
In this example the libraries will not being imported.
EDIT:
This does work on Windows but not on linux, my case: Rasbian OS.
Does anyone know why this doesn't work?
Thanks in advance!
1 Answer 1
By looking at your code, I think you are on micropython. If this is the case, according to the doc, environ is not implemented yet.
By quoting the doc, the suggestion seems to be the following:
Workaround: Use getenv, putenv and unsetenv
5 Comments
environ['DISCOVERY_ENV'] = "test" print(environ.get('DISCOVERY_ENV'))
? I mean, in the same .py script, just to check if there is an issue that's not on python side. For example it could happens that the first portion of your code and the second ones belongs to 2 different python files and they are executed in a different context.
environ.get('DISCOVERY_ENV')
?