I really wanted to separate the processing at the time of testing. Let's judge from the file name of the runtime argument using sys.argv.
import sys
if 'test_loader.py' in sys.argv:
db = load_database('test')
else:
db = load_database('production')
runtime
python test_loader.py
But if you need to call test_loader from another script, this is not the way to go. ..
os.environ
.
15.1. Os — Miscellaneous operating system interfaces Python 2.7ja1 documentationtest_loader.py:
import os
if not os.getenv('DB'):
os.environ['DB'] = 'test'
Recommended Posts