title: how to loop list to pass string to function name in python
body: <p>I'm trying to find the most efficient way to create different function name <strong>myfunction_a</strong> ,.. b , c   with slightly different code ( input file name <strong>'app/data/mydata_a.csv'</strong> )  so here below is the <strong>a</strong> function I got </p>
  
  <pre><code>def myfunction_a(request):
  
      os.getcwd()  # Should get this Django project root (where manage.py is)
      fn = os.path.abspath(os.path.join(os.getcwd(),'app/data/mydata_a.csv'))
      # TODO: Move to helper module
      response_data = {}
      data_format = 'tsv'
      if data_format == 'json':
          with open(fn, 'rb') as tsvin:
              tsvin = csv.reader(tsvin, delimiter='\t')
  
              for row in tsvin:
                  print 'col1 = %s  col2 = %s' % (row[0], row[1])
                  response_data[row[0]] = row[1]
          result = HttpResponse(json.dumps(response_data), content_type = 'application/json')
      else:
          with open(fn, 'rb') as tsvin:
              buff = tsvin.read()
          result = HttpResponse(buff, content_type = 'text/tsv')
      return result
  </code></pre>
  
  <p>I want to be able to loop through my list and create multiple function name: </p>
  
  <pre><code>mylist = ['a','b','c' ... 'z' ]
  </code></pre>
  
  <p>def myfunction_a(request):
      ...  ( 'app/data/mydata_a.csv' ) 
      return request</p>
  
  <p>to get final result of : </p>
  
  <ul>
  <li>def myfunction_a  => taking 'app/data/mydata_a.csv'  </li>
  <li>def myfunction_b => taking 'app/data/mydata_b.csv' </li>
  <li>def myfunction_c  => taking 'app/data/mydata_c.csv'</li>
  </ul>
  
  <p>right now I just copy and past and change it. is there a better to do this ? Any recommendation would be appreciated. Thanks.</p>