Advertisement
sanfx

show.py

Mar 8th, 2013
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.03 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. import os, sys
  4.  
  5. variable =  sys.argv
  6.  
  7. def enVar(variable):
  8.         """
  9.        This function returns all the environment variable set on the machine or in active project.
  10.        if environment variable name is passed to the enVar function it returns its values.
  11.        """
  12.         nVar = len(sys.argv)-1
  13.         if len(variable) == 1: # if user entered no environment variable name
  14.                 for index, each in enumerate(sorted(os.environ.iteritems())):
  15.                         print index, each
  16.         else: # if user entered one or more than one environment variable name
  17.                 for x in range(nVar):
  18.                         x+=1
  19.                         if os.environ.get(variable[x].upper()): # convertes to upper if user mistakenly enters lowecase
  20.                                 print "%s : %s" %  (variable[x].upper(), os.environ.get(variable[x].upper()))
  21.                     else: print 'Make sure the Environment variable "%s" exists or spelled correctly.' % variable[x]
  22.  
  23. enVar(variable)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement