title: How to pass data variable from a python/flask code to another python code?
body: <p>Hello I am currently a noob in Python and need to implement this for a homework, I would appreciate a lot your help please!</p>
  
  <p>Currently I have this python code with flask implemented that sends input values from several text boxes in my HTML to my code and I can view the result in cmd prompt, but this "values" need to be input into another large python script with no flask so it can work. This variables are like the input variables for that code to work. How can I do that? I've tried "import from" and things like that but it doesn´t work, I don´t know if it is because how the function is constructed or my syntax, sorry if this is way to easy I would appreciate a lot your help! (some things are wrote in spanish but its only strings and variable names)</p>
  
  <p>Leave my python/flask code below 'gettingtextvalue.py': </p>
  
  <pre><code>    from flask import Flask, request, render_template
  
  app = Flask(__name__)
  
  #class TestDatos():
  
  @app.route('/')
  def my_form():
      return render_template('from_ex.html')
  
  @app.route('/', methods=['POST'])
  def my_form_post():
      num = request.form['a']
      dist = request.form['b']
      fallaPer = request.form['c']
      fallaCen = request.form['d']
      gen = request.form['e']
      reb = request.form['f']
  
      numInt = int(num)
      distInt = int(dist)
      fallaPerInt = int(fallaPer)
      fallaCenInt = int(fallaCen)
      genInt = int(gen)
      rebInt = int(reb)
  
      print "Numero de computadoras: ", numInt
      print "Distribucion de trabajos: ", distInt
      print "Falla en comp perifericas: ", fallaPerInt
      print "Falla en comp central: ", fallaCenInt
      print "Generacion de trabajos: ", genInt
      print "Recuperacion despues de falla: ", rebInt
  
      return (numInt, distInt, fallaPerInt, fallaCenInt, genInt, rebInt)
  
  def operacion():
      print("Prueba", numInt)
  
  if __name__ == "__main__":
      app.run()
  
  </code></pre>
  
  <p>And my HTML here: </p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html lang="en" dir="ltr"&gt;
    &lt;head&gt;
      &lt;meta charset="utf-8"&gt;
      &lt;title&gt;Title&lt;/title&gt;
    &lt;/head&gt;
    &lt;body&gt;
      &lt;form method="post"&gt;
        &lt;p&gt;Login&lt;/p&gt;&lt;br&gt;
  
        &lt;input name = "a"&gt;
        &lt;input name = "b"&gt;
        &lt;input name = "c"&gt;
        &lt;input name = "d"&gt;
        &lt;input name = "e"&gt;
        &lt;input name = "f"&gt;
  
        &lt;input type = "submit"&gt;
  
      &lt;/form&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>This is the other test script 'ejemplo.py' (not my final one): </p>
  
  <pre><code>from gettingtextvalue import my_form_post
  print my_form_post()
  
  </code></pre>
  
  <p>This is what cmd displays from running 'gettingtextvalue.py':</p>
  
  <pre><code>Numero de computadoras:  1
  Distribucion de trabajos:  2
  Falla en comp perifericas:  3
  Falla en comp central:  4
  Generacion de trabajos:  5
  Recuperacion despues de falla:  6
  [2020-05-30 22:13:24,328] ERROR in app: Exception on / [POST]
  Traceback (most recent call last):
    File "C:\Python27\lib\site-packages\flask\app.py", line 2447, in wsgi_app
      response = self.full_dispatch_request()
    File "C:\Python27\lib\site-packages\flask\app.py", line 1953, in full_dispatch_request
      return self.finalize_request(rv)
    File "C:\Python27\lib\site-packages\flask\app.py", line 1968, in finalize_request
      response = self.make_response(rv)
    File "C:\Python27\lib\site-packages\flask\app.py", line 2090, in make_response
      "The view function did not return a valid response tuple."
  TypeError: The view function did not return a valid response tuple. The tuple must have the form (body, status, headers), (body, status), or (body, headers).
  </code></pre>
  
  <p>This is the error while running 'ejemplo.py':</p>
  
  <pre><code>RuntimeError: Working outside of request context.
  
  This typically means that you attempted to use functionality that needed
  an active HTTP request.  Consult the documentation on testing for
  information about how to avoid this problem.
  </code></pre>