I have a script which requires some environment variables to be set in order to work.
I am looking for a way to load the required .env
files only when it is run as a standalone script. The variables are expected to be present if the script is imported by another program and it should not explicitly load the .env
files.
The solution I came up with was having an additional if __name__ == "__main__"
statement at the top of the script but I have never seen this done before.
How else can I solve this problem?