Home > life is fun > Python environment auto detection

Python environment auto detection

Happy Thanksgivings folks!

Figured out a great way to get rid of environment dependent element for Python dev / production code.

The following code will basically :

  1. detect the hostname.
  2. based on the detected hostname, set the ENV_MODE variable for your following code condition branching, for dev / prod.

import socket
hostname = socket.gethostname()

# Auto detect environment 20151129 : ENV MODE: 1: EC2 ; 2: LOCAL TEST.
if(hostname == ‘victorfang-laptop’):

Categories: life is fun
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: