pebox11
pebox11

Reputation: 3748

Calling a python script from shell but passing the location of config file as a parameter

How can I call a function from a python script (Ubuntu shell) but also pass a config parameter at the same time? A relevant SO post does not seem to address that.

This is what I have for now:

$ python -c ' from python_library import * ; function() ; -config /path/to/config/file '

The above fails. And so do the following (as many other) combinations:

    $ python -c ' from python_library import * ; function() -config /path/to/config/file '

or

    $ python -c ' from python_library import * ; function() ; -config "/path/to/config/file" '

Thanks!

Upvotes: 0

Views: 405

Answers (2)

avigil
avigil

Reputation: 2246

You need to pull the conf arg out as another argument to python

$ python -c ' from python_library import * ; function()' -config /path/to/config/file

Upvotes: 1

Andrej Kesely
Andrej Kesely

Reputation: 195573

You could use environment variable for that:

MYPARAMETERS="-config /path/to/config/file" python -c "import os,sys;sys.argv = os.environ['MYPARAMETERS'].split(); import python_library import * ; function()"

Upvotes: 1

Related Questions