set external input in python program


Simone Bolognini

I want to do something like in my python code

python my_prog.py -inp 3 -inp2 4

and was able to use inp and inp2 as input in my python program. what should I do?

Scheldt 222888

You can use getopt to parse input parameters.

Example from docu:

import getopt, sys

def main():
    try:
        opts, args = getopt.getopt(sys.argv[1:], "ho:v", ["help", "output="])
    except getopt.GetoptError as err:
        # print help information and exit:
        print str(err) # will print something like "option -a not recognized"
        usage()
        sys.exit(2)
    output = None
    verbose = False
    for o, a in opts:
        if o == "-v":
            verbose = True
        elif o in ("-h", "--help"):
            usage()
            sys.exit()
        elif o in ("-o", "--output"):
            output = a
        else:
            assert False, "unhandled option"
    # ...

if __name__ == "__main__":
    main()

Related


Java simulates user input to an external program

Ynjxsjmh : I need to use a Python program to calculate something and get a result. The Python program requires input so long that it cannot be passed as an argument when calling the Python program. I will simplify this question. This is a Python program that w

Unable to import external Python program using Selenium

Marshall Cocop I'm having a small problem with Selenium on Python. In the main script below (bottom right), I just want to manage to execute another external python script. import time, os import re #regex import uuid import urllib import subprocess, sys impor

set external input in python program

Simone Bolognini I want to do something like in my python code python my_prog.py -inp 3 -inp2 4 and was able to use inp and inp2 as input in my python program. what should I do? Scheldt 222888 You can use getopt to parse input parameters. Example from docu: i

Running an external program (executable) in Python?

Happy: I'm new to Python and have been trying to run external executables from Python. I have an executable of a program written in Fortran. Suppose the executable is named flow.exe. My executable is in C:\Documents and Settings\flow_model. I tried both the os

python exe error when run by external program

Omid I have python exe file made with cx_Freeze. Basically the script uses the text file "XYZ.txt" to generate the word cloud. When i run the python exe file everything is fine and the code runs fine but i plan to run it from an external program (a game that g

Python 2.7 run external .py file in program

Owen Strand I have a .py file and I want to make it so that I can type its name in another .py file and have it run all the code in the first file. Remember, this is in Python 2.7 on a Raspberry Pi 3. Thanks! Upaka Podel Then you can use execfile() or os.syste

External input to Python programs at runtime

m I am creating a test automation program which uses an application without any interface. However, the app calls a batch script when changing modes, so I'm able to capture mode transitions. What I want to do is get the batch script to provide input to my pyth

Set input value using Javascript on external click

Valerio Massari I want to set max value for digital input. I used the "max" HTML attribute, but the user can still write a number on the max value. After the user has set the input to the max value, is there any way to reset the value of that input to the max

Unable to import external Python program using Selenium

Marshall Cocop I'm having a small problem with Selenium on Python. In the main script below (bottom right), I just want to manage to execute another external python script. import time, os import re #regex import uuid import urllib import subprocess, sys impor

How to open an external program in Python

lightning fast Repeat edit: No, I did, but it didn't want to start Firefox. I'm working on a cortana/siri assistant or something and I want it to say open a web browser when I say something. So I've done the if part, but I just need it to start firefox.exe, I'

Unable to import external Python program using Selenium

Marshall Cocop I'm having a small problem with Selenium on Python. In the main script below (bottom right), I just want to manage to execute another external python script. import time, os import re #regex import uuid import urllib import subprocess, sys impor

Set input value using Javascript on external click

Valerio Massari I want to set max value for digital input. I used the "max" HTML attribute, but the user can still write a number on the max value. After the user has set the input to the max value, is there any way to reset the value of that input to the max

How to open an external program in Python

lightning fast Repeat edit: No, I did, but it didn't want to start Firefox. I'm working on a cortana/siri assistant or something and I want it to say open a web browser when I say something. So I've done the if part, but I just need it to start firefox.exe, I'

run external python program from another program

Laxmi Kadariya I have a python program gold.py located at /home/laxmi/Desktop/gold/gold.py on Ubuntu. I have a python program test.py as test.py import subprocess subprocess.Popen("python", "Desktop/gold/gold.py") I want the program to call the gold.py progra

Set input value using Javascript on external click

Valerio Massari I want to set max value for digital input. I used the "max" HTML attribute, but the user can still write a number on the max value. After the user has set the input to the max value, is there any way to reset the value of that input to the max

Common Lisp: write external program input

User 1453428 I want to write a simple wrapper for mpg123 console mp3 player in CL/CCL and would like to know how to write to mpg123 that exists as a spawned process: (let* ((p (run-program "mpg123" '("-R") :input :stream :output :stream :wait nil)) (s (

Custom input from Java program to Python program

Samudra Ganguly I'm trying to make a full-fledged Java program that runs a python program. The python program is as follows: print('Enter two numbers') a = int(input()) b = int(input()) c = a + b print(c) If I execute this code, the terminal looks like this:

Running an external program (executable) in Python?

Happy: I'm new to Python and have been trying to run external executables from Python. I have an executable of a program written in Fortran. Suppose the executable is named flow.exe. My executable is in C:\Documents and Settings\flow_model. I tried both the os

Set input value using Javascript on external click

Valerio Massari I want to set max value for digital input. I used the "max" HTML attribute, but the user can still write a number on the max value. After the user has set the input to the max value, is there any way to reset the value of that input to the max

Set input value using Javascript on external click

Valerio Massari I want to set max value for digital input. I used the "max" HTML attribute, but the user can still write a number on the max value. After the user has set the input to the max value, is there any way to reset the value of that input to the max

External input to Python programs at runtime

m I am creating a test automation program which uses an application without any interface. However, the app calls a batch script when changing modes, so I'm able to capture mode transitions. What I want to do is get the batch script to provide input to my pyth

Set input value using Javascript on external click

Valerio Massari I want to set max value for digital input. I used the "max" HTML attribute, but the user can still write a number on the max value. After the user has set the input to the max value, is there any way to reset the value of that input to the max

run external python program from another program

Laxmi Kadariya I have a python program gold.py located at /home/laxmi/Desktop/gold/gold.py on Ubuntu. I have a python program test.py as test.py import subprocess subprocess.Popen("python", "Desktop/gold/gold.py") I want the program to call the gold.py progra

set external input in python program

Simone Bolognini I want to do something like in my python code python my_prog.py -inp 3 -inp2 4 and was able to use inp and inp2 as input in my python program. what should I do? Scheldt 222888 You can use getopt to parse input parameters. Example from docu: i

Common Lisp: write external program input

User 1453428 I want to write a simple wrapper for mpg123 console mp3 player in CL/CCL and would like to know how to write to mpg123 that exists as a spawned process: (let* ((p (run-program "mpg123" '("-R") :input :stream :output :stream :wait nil)) (s (

How to open an external program in Python

lightning fast Repeat edit: No, I did, but it didn't want to start Firefox. I'm working on a cortana/siri assistant or something and I want it to say open a web browser when I say something. So I've done the if part, but I just need it to start firefox.exe, I'

Running an external program (executable) in Python?

Mesut: I'm new to Python and have been trying to run external executables from Python. I have an executable of a program written in Fortran. Suppose the executable is named flow.exe. My executable is in C:\Documents and Settings\flow_model. I tried both the os