old_contents: from __future__ import print_function
  import os
  import numpy as np
  
  SAMPLES = 1201  # Change this to 3601 for SRTM1
  HGTDIR = 'hgt'  # All 'hgt' files will be kept here uncompressed
  
  
  def get_elevation(lon, lat):
      hgt_file = get_file_name(lon, lat)
      if hgt_file:
          return read_elevation_from_file(hgt_file, lon, lat)
      # Treat it as data void as in SRTM documentation
      # if file is absent
      return -32768
  
  
  def read_elevation_from_file(hgt_file, lon, lat):
      with open(hgt_file, 'rb') as hgt_data:
          # HGT is 16bit signed integer(i2) - big endian(>)
          elevations = np.fromfile(hgt_data, np.dtype('>i2'), SAMPLES*SAMPLES)\
                                  .reshape((SAMPLES, SAMPLES))
          
          lat_row = int(round((lat - int(lat)) * (SAMPLES - 1), 0))
          lon_row = int(round((lon - int(lon)) * (SAMPLES - 1), 0))
          
          return elevations[SAMPLES - 1 - lat_row, lon_row].astype(int)
  
  
  def get_file_name(lon, lat):
      """
      Returns filename such as N27E086.hgt, concatenated
      with HGTDIR where these 'hgt' files are kept
      """
  
      if lat >= 0:
          ns = 'N'
      elif lat < 0:
          ns = 'S'
  
      if lon >= 0:
          ew = 'E'
      elif lon < 0:
          ew = 'W'
  
      hgt_file = "%(ns)s%(lat)02d%(ew)s%(lon)03d.hgt" % {'lat': abs(lat), 'lon': abs(lon), 'ns': ns, 'ew': ew}
      hgt_file_path = os.path.join(HGTDIR, hgt_file)
      if os.path.isfile(hgt_file_path):
          return hgt_file_path
      else:
          return None
  
  
  if __name__ == '__main__':
      # Mt. Everest
      print(get_elevation(86.925278, 27.988056))
      # Kanchanjunga
      print(get_elevation(88.146667, 27.7025))
  
new_contents: from __future__ import print_function
  import os
  import numpy as np
  
  SRTM_DICT = {'SRTM1' : 3601, 'SRTM3' : 1201}
  SRTM_type = os.getenv('SRTM_TYPE', 'SRTM1') # Get the type of SRTM files or 
                                              # use SRTM1 by default
  SAMPLES = SRTM_DICT[SRTM_type]
  HGTDIR = os.getenv('HGT_DIR', 'hgt')  # Get OS env. location of files, 
                                        # or default to 'hgt', where files 
                                        # should be kept uncompressed
  
  def get_elevation(lat, lon):
      hgt_file = get_file_name(lat, lon)
      if hgt_file:
          return read_elevation_from_file(hgt_file, lat, lon)
      # Treat it as data void as in SRTM documentation
      # if file is absent
      return -32768
  
  def read_elevation_from_file(hgt_file, lat, lon):
      with open(hgt_file, 'rb') as hgt_data:
          # HGT is 16bit signed integer(i2) - big endian(>)
          elevations = np.fromfile(hgt_data, np.dtype('>i2'), SAMPLES*SAMPLES)\
                                  .reshape((SAMPLES, SAMPLES))
          
          lat_row = int(round((lat - int(lat)) * (SAMPLES - 1), 0))
          lon_row = int(round((lon - int(lon)) * (SAMPLES - 1), 0))
          
          return elevations[SAMPLES - 1 - lat_row, lon_row].astype(int)
  
  def get_file_name(lat, lon):
      """
      Returns filename such as N27E086.hgt, concatenated
      with HGTDIR where these 'hgt' files are kept
      """
      if lat >= 0:
          ns = 'N'
      elif lat < 0:
          ns = 'S'
  
      if lon >= 0:
          ew = 'E'
      elif lon < 0:
          ew = 'W'
  
      hgt_file = "%(ns)s%(lat)02d%(ew)s%(lon)03d.hgt" % \
                 {'lat': abs(lat), 'lon': abs(lon), 'ns': ns, 'ew': ew}
      hgt_file_path = os.path.join(HGTDIR, hgt_file)
      if os.path.isfile(hgt_file_path):
          return hgt_file_path
      else:
          return None
  
  if __name__ == '__main__':
      # Mt. Everest
      print('Mt. Everest: %d' % get_elevation(27.988056, 86.925278))
      # Kanchanjunga
      print('Kanchanjunga: %d' % get_elevation(27.7025, 88.146667))
  
subject: Allow OS env variables. Change param ordering.