How to resolve this bash python interaction? -
i have 3 files, let's see 1 one.
params.conf
[a] [b] [c] [d] [e] parsing.py
from configparser import safeconfigparser parser = safeconfigparser() parser.read('params.conf') lst=parser.sections() print lst demo.sh
#! /bin/bash value=$(python parsing.py) echo "$value" after running demo.sh, should output ['a','b','c','d','e'] , getting that.
but, there several problem when going next level.
i want use list elements, @ moment need use
sedparse within bash file don't want, rather love accesslistarray in bash can use later.currently printing
list, can't that. because have multiplelistin python file, , can't afford print each of them , retrieve bash. so, can return variable python bash somehow, searching hacksourcebashfilebashfile.eventually want have multiple functions in
pythonfile , try access particular functions return value bash. can achieve that? rather calling wholepythonfile, can call specificfunctionpythonfile?
you not need use sed parse output of python script.
in python script before printing output, convert list space separated string (hope not have item in list space in it)
print " ".join(lst) this output can looped through in shell. me following code gives below output.
#! /bin/bash lst=$(python parsing.py) in $lst echo $i done params.conf same yours...
output
a b c d e hope helps in solving of problem..
also calling specific function in python shell script can achieved below...
python file multiple function
import sys def foo(): print 'i foo' def func(): print 'i func' def bye(): print 'i bye' if __name__ == "__main__": if len(sys.argv)==2: x = getattr(sys.modules[__name__], sys.argv[1]) x() and shell script (i using command line args name python function)
#! /bin/bash echo $(python params.py $1) output...
# ./demo.sh foo foo # ./demo.sh func func # ./demo.sh bye bye
Comments
Post a Comment