0

My python file: /root/src/foo.py

#/root/src/foo.py

def add(a,b):
    '''add(a,b) --> a+b'''
    return a+b
      

How do I call foo.add(a,b) from a shell script? I got this suggestion from somewhere:

python -c "import foo; print(foo.x(1, 2))"

But it won't work if the shell script and foo.py are in a separate locations.

1 Answer 1

2

you need to add the folder to your pythonpath

PYTHONPATH=/path/to/foo python -c "import foo;print(foo.add(5,6))"

should work (in this case it just sets pythonpath, not adds to it)

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

Comments

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.