Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从另一个目录的shell脚本调用python函数_Python_Bash - Fatal编程技术网

从另一个目录的shell脚本调用python函数

从另一个目录的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

我试图使用python脚本中的函数并将其存储到另一个目录中shell脚本中的变量中,以下是目录的可视化表示:

    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脚本,这就是为什么我要问,再次抱歉。