Passing parameter to Python Program

I have a client who would like independent and dependent variables names to be non-static. Python unlike SAS does not use macro variables or supports macro variables.

I know how to pass parameters using a Python Function. However, I have the need to pass independent and dependent variables into the Python program and use values which presuming will be passed to a defined variable inside the program. I know this can be accomplished using the command line; however, the client doesn’t want to use the command line approach.

As an example, I need to do something like what outlined below as the end goal is to automate execution of the Python program as a Stored Procedure.

Test_Python (Parm1, Parm2, Parm3, Parm4)

Field1 = Parm1
Field2 = Parm2
Field3 = Parm3
Field4 = Parm4

DF = pd.dataframe([Field1, Field2, Field3, Field4])

Could you clarify what you mean by “pass independent and dependent variables into the Python program”? And why using a function doesn’t work for your use case?

Maybe what you’re looking for is a class that holds the “independent variables” and models the “dependent variables” by maintaining invariant or by exposing them as properties?

1 Like

The alternative to command-line entry is a user interface, especially a GUI. The advantage of the latter is that one can change settings and click a ‘GO’ button to initiation new calculation with new settings.

Hello,

Is your client interested in a GUI approach? Your client would like to enter the three values in a
window? If so, there is tkinter (a GUI design package library) which comes with Python (there are others of course). Once your client has entered the three values, a button that is associated with this function (Test_Python) may be clicked which then would call the function to execute.

The request may not be clear but there may well be lost of answers if we understood it better.

If I understand the request, the OP (or more specifically their client) has some info they do not want embedded in the program but which should in some sense be inserted into the program for a particular run.

Some have offered using a GUI, and having them fill out a form or in some way make selections. That seems reasonable, albeit perhaps overkill.

Some input() statement might serve a similar purpose at run time.

Farther afield, is the dynamic data could be anywhere the program can access and it can read a file using endless methods such as four unformatted lines, or a JSON construct or from an excel spreadsheet/tab and so on.

And, of course, a python program can be dynamically created by anything (else) and then run. You can write a script, such as in a shell, that simply prepends a few lines to an existing python program that set up the four variables and create a temporary python program that it then invokes.

You can set environment variables that the python program looks for. If using an environment with a shell like bash that supports “here documents” you can put in a python program to be read in as sort of from stdin in which the variables get interpolated.

The question is what the client actually wants and is willing to do. It can range from a program running on different machines and being able to set the four variables without any further human intervention to having them type in or select from choices.