1

Can some one help me with the syntax, how to call 'x' function from a shell script. The challenge here is, from shell script need to pass a,b dynamically.

your suggestion greatly appreciated.

Python Code:

def x(a,b):
    '''x(a,b) --> [a,b]'''
    return [a,b]

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

def test():
    '''test code for all modules'''
    print "testing x..."
    print x(1,2)
    print x('a','b')
    print x([1,2,3],[4,5,6])
    print "testing add..."
    print add(1,2)
    print add('a','b')
    print add([1,2,3],[4,5,6])
    return
Mad Physicist
  • 107,652
  • 25
  • 181
  • 264
SVN
  • 13
  • 1
  • 4

1 Answers1

5

If you save the file foo.py, you can run this from the shell

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

The result can be read from stdout.

John La Rooy
  • 295,403
  • 53
  • 369
  • 502