从另一个目录的shell脚本调用python函数
我试图使用python脚本中的函数并将其存储到另一个目录中shell脚本中的变量中,以下是目录的可视化表示:从另一个目录的shell脚本调用python函数,python,bash,Python,Bash,我试图使用python脚本中的函数并将其存储到另一个目录中shell脚本中的变量中,以下是目录的可视化表示: xxx/ aaa.sh yyy/ sample.py 这是sample.py的代码 import ConfigParser def getval(section, key): config = ConfigParser.RawConfigParser() config.read("sample.confi
xxx/
aaa.sh
yyy/
sample.py
这是sample.py的代码
import ConfigParser
def getval(section, key):
config = ConfigParser.RawConfigParser()
config.read("sample.config")
return config.get(section, key)
这是aaa.sh的一部分
#!/bin/sh
Path = $(python -c 'import imp; lp = imp.load.source('sample', 'path/to/sample.py'), print lp.getval('section_1', 'key_1')')
some code.......
echo $Path
我的问题是我没有得到路径的任何值,我想我在如何调用python脚本函数方面有错误,我不知道那是什么部分。
有人能帮我吗。提前谢谢
我结合了这个问题中的EOL思想和这个问题中的Sebastian Rittau思想。尝试:
Path=$(python -c 'import imp; lp = imp.load.source("sample", "path/to/sample.py"); print lp.getval("section_1", "key_1")')
很抱歉,我不熟悉shell脚本,这就是为什么我要问,再次抱歉。