1

I have a python file that takes in 6 parameters from the command line and runs.

python_file.py param1, param2, param3, param4, param5, param6

What I would like to do is pass the parameters from a web app using flask with bootstrap. Each parameter needs to have the option from the front end to select what parameter the user chooses. Example of what I am looking for on the front end below is:

Param1_drop_down:  Param2 drop_down:
- option1          - option1 etc..
- option2
- option3
- option4

Any ideas on this? I am new to front end work so any help would be greatly appreciated.

2
  • What exactly is your question? Is it how to create a web app with dropdown options? Or do you already have that web app and you wonder how to send data from it to a Flask server that would pass them to your Python file? Commented Oct 9, 2019 at 16:13
  • @AlexanderRossa it is really both of those. Commented Oct 9, 2019 at 16:20

1 Answer 1

1

Since you are using the command line to receive the args, I recommend the usage of subprocess.Popen, with that you can run your script in the same way, Popen expects you to run a bash command, you can easily use it to execute your python file with the args chosen by the users.

edit to be more clear: Lets say you have this python script.

from time import sleep
count = 0
while True:
    print("Hello", count)
    count += 1
    sleep(10)

And you want to call it from another script, you can use subprocess.Popen to do this for you.

i.e

import subprocess

process = subprocess.Popen(["python3","yourfile.py"])

#Do something more while the other process is running

You can also redirect the Popen output to a variable and do some work with the return of your code.

Sign up to request clarification or add additional context in comments.

2 Comments

what if I just need the parameters to be passed straight to the python file without using the command line? Is that what you are saying this option does?
I've added more information on my answer. Yes, it will run as a command line, but it will be runned directly from your code, so, you can manipulate which args you want to use.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.