title: Dynamic python/flask route function naming
body: <p>first off, a disclaimer: I'm not well versed in python or flask, so bear with me.</p>
  
  <p>I'm trying to put together a minimal API using flask, i was planning to dynamically generate routes and their associated procs from the contents of a subdirectory.
  The code looks something like this:</p>
  
  <pre><code>from flask import Flask
  import os
  app = Flask(__name__)
  configs = os.getcwd() + "/configs"
  for i in os.listdir(configs):
      if i.endswith(".json"):
          call = "/" + os.path.splitext(i)[0]
          @app.route(call, methods=['POST'])
          def call():
              return jsonify({"status": call + "Success"}), 200
  </code></pre>
  
  <p>The plan being to iterate over a bunch of config files and use their naes to define the routes. Now, this works for a single config file, but wont work for multiple files as I end up trying to overwrite the function <code>call</code> that is used by each route.</p>
  
  <p>I can factor out most of the code to a separate function as long as i can pass in the call name. However it seems that however i go about this i need to dynamically name the function generated and mapped to the route.</p>
  
  <p>So, my question is: how can use the contents of a variable, such as 'call' to be the function name?</p>
  
  <p>i.e. something like</p>
  
  <pre><code>call = "getinfo"
  def call():  # Effectively being evaled as def getinfo():
  </code></pre>
  
  <p>Everything i've tried hasn't worked, and i'm not confident enough in my python syntax to know if it's because i'm just doing something silly.</p>
  
  <p>Alternatively is there another way to do what i'm trying to achieve?</p>
  
  <p>Thanks for all and any feedback!</p>