-3

i'm trying to use a function from a python script and store it to a variable in a shell script from another directory,here's the visual representation of the directories:

    xxx/
        aaa.sh
    yyy/
        sample.py

here's the code of the sample.py

    import ConfigParser

    def getval(section, key):
    config = ConfigParser.RawConfigParser()
    config.read("sample.config")
    return config.get(section, key)

and here is some part of the 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

my problem was i don't get any value of the Path,i think i have mistake on how will i call the python script function,i don't know what part is that. can anyone help me. thanks in advance.

i combined the idea of EOL from this question Calling a Python function from a shell script and the idea of Sebastian Rittau from this question How to import a module given the full path?.

1
  • i'm sorry but i'm not familiar with shell script that's why i'm asking,sorry again. Commented Aug 24, 2012 at 8:07

1 Answer 1

1

Try:

Path=$(python -c 'import imp; lp = imp.load.source("sample", "path/to/sample.py"); print lp.getval("section_1", "key_1")')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.