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
  • 95,415
  • 23
  • 151
  • 231
SVN
  • 13
  • 4

1 Answers1

4

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
  • 281,034
  • 50
  • 354
  • 495