title: Import with multiple arguments: running python script in flask
body: <p>I have a python script main.py that takes in two arguments (2 text files)</p>
  
  <p>I'm using MAC OS X
  Python 2.7</p>
  
  <p>This runs easily on terminal with:</p>
  
  <pre><code>python main.py train.txt sample.txt
  </code></pre>
  
  <p>I have now developed a small front-end using Flask with very minor HTML as follows:</p>
  
  <pre><code>  #front.py FLASK
    from flask import Flask, render_template, request, redirect
    app = Flask(__name__)
  
    @app.route('/')
    def hello_world():
    return render_template('index.html')
  
    @app.route('/signup', methods = ['POST'])
     def signup():
      email = request.form['email']
      email1 = request.form['email1']
      # command below is just for testing, I wish to implement the same as this would if this would be typed in terminal.
      print("main.py " + email + " " + email1) 
     return redirect('/')
  
   if __name__ == "__main__":
    app.run()
  </code></pre>
  
  <p>and the HTML </p>
  
  <pre><code> &lt;!DOCTYPE html&gt;
     &lt;html&gt;
       &lt;head&gt;
         &lt;title&gt;T&lt;/title&gt;
       &lt;/head&gt;
  
       &lt;body&gt;
         &lt;form action="/signup" method="post"&gt;
         &lt;input type="text" name="email"&gt;&lt;/input&gt;
         &lt;input type="text" name="email1"&gt;&lt;/input&gt;
         &lt;input type="submit" value="Signup"&gt;&lt;/input&gt;
         &lt;/form&gt;
      &lt;/body&gt;
    &lt;/html&gt;
  </code></pre>
  
  <p>This HTML code is simply using a form to take in the 2 arguments ( I find this easier than JS as I have no experience with that). </p>
  
  <p>I have just written the </p>
  
  <pre><code>    print("main.py " + email + " " + email1)
  </code></pre>
  
  <p>command above to test, it's not of any utility for now.</p>
  
  <p>Usage of the parameters:</p>
  
  <pre><code>  #main.py
  
    from filter import Filter
    import sys
  
    # Get arguments from user
    train = sys.argv[1]
    messages = sys.argv[2]
  
    # Open files for reading and writing
    train_file = open(train, "rb")
    messages_file = open(messages, "rb")
    predictions_file = open("predictions.txt", "w")
  
   # Create new filter and train it using the train-file
   f = Filter()
  f.train(train_file)
  
   #filter the messages in messages_file, write results to predictions_file
   f.filter(messages_file, predictions_file)
  
  # Close all the files
   train_file.close()
   messages_file.close()
   predictions_file.close()
  </code></pre>
  
  <p>I wish to now run my script which is main.py via this flask application itself, and want to know how this is possible.</p>
  
  <p>I was using import main with another app decorator say /exec and manually changing the URL to go from 127.0.0.2000 to 127.0.0.2000/exec but this was giving errors as main requires the arguments to be passed.</p>
  
  <p>Sorry if I'm unclear in explaining the problem, please let me know if I can explain anything in a better way to help understand the problem.</p>
  
  <p>Thank you</p>