Executing a Python Script with flags


A colleague of mine has created a a python script for me which does something very neat.
It requires that flags are set in the script so for example script.py -h
I am trying to get it to run in R using the reticulate package based on the documentation i found here

In python command prompt I can type something like this

(base) C:\Users\foo\neat-util>python util.py -h
usage: ['-h'] [-h] [-n N] [-r R]

optional arguments:
  -h, --help  show this help message and exit

I tried the same thing in R but get the following error

py_run_file("C:/Users/foo/neat-util/util.py -h")

# Error in py_run_file_impl(file, local, convert) : 
# Unable to open file 
# (does it exist?)

If i remove the flag it finds the file but then falls over because the flag is necessary to run the script.
Can anyone help?

Thank you for your time

I don't use reticulate myself so I'm not talking as an expert.. but taking a guess.
Perhaps reticulates source_python() should be used, and then you can call the function inside the source, passing whatever arguments may be needed ?

Hi @nirgrahamuk

While i was not able to get it working with reticulate. I was able to get a workaround using the systemmd call as outlined here


The CPython interpreter scans the command line and the environment for various settings.

You can list the files and directories in the command line using Python and scans the various settings including CPython implementation detail and other implementations’ command line schemes may differ.

You can implement that.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.