Quantcast
Channel: RasadaCrea rss feeds aggregator
Viewing all articles
Browse latest Browse all 176

Configuring your Python application using environment variables

$
0
0
This blog post is a short explanation how to give and consume environment variables in your (Python) code. It's a nice little trick, but if you are not well-versed in UNIX systems you might not know it. Table Of Content 1. Configuring your application 2. Using environment variables in UNIX 3. Another trick: socket.gethostname() Please see the original blog post for syntax color examples. 1. Configuring your application An application can be configured usually in three ways. Through command-line arguments (I prefer simplistic plac library with Python) configuration files (I prefer YAML or Python standard library ConfigParser for INI style files) environment variables The two first ones are the most well-known methods. However, the last option is the easiest for quick and dirty hacks. 2. Using environment variables in UNIX Note: Environment variables work alike in UNIX and Windows. However, I have no longer valid experience about Windows and how to set environment variables in the latest cmd.exe incarnations. (I used to write AUTOEXEC.bats for DOS, but that's like long time ago). So if there are Windows gurus around please leave a comment. Environment variables are Easy way to make deployment specific .. cntd

Viewing all articles
Browse latest Browse all 176

Trending Articles