code: def swap_coords(filename):
      
  
      # Read from input file
      fid = open(filename, 'r')
      lines = fid.readlines()
      fid.close()
  
      # Open output file
      basename, ext = os.path.splitext(filename)
      fid = open(basename + '_converted' + ext, 'w')
  
      # Report
      N = len(lines)
      print 'There are %i lines in %s' % (N, filename)
  
      # Process
      reading_positions = False
      got_lat = False
      got_lon = False
      for k, line in enumerate(lines):
          s = line.strip()
          if s.startswith(position_tag):
              # Swap lat and lon pairs in this line and write back
              fid.write(swap_pairs(line))
          elif s.startswith(lc_tag):
              fid.write(swap_pairs(line, starttag=lc_tag))
          elif s.startswith(uc_tag):
              fid.write(swap_pairs(line, starttag=uc_tag))
          else:
              # Store back unchanged
              fid.write(line)
  
      fid.close()
docs: Swap lat and lon in filename