3

For example, in bash:

python my_py.py
    # i get some variable my_var

Back to bash. I want to have $my_var!

brastein
  • 77
  • 5
  • 7
    print the variable, and only the variable to terminal. Then, in bash you can assign the output to a variable using process substitution: `myVar=$(python my.py)` – hek2mgl Aug 23 '13 at 10:51
  • Have a look at http://stackoverflow.com/questions/5971312/how-to-set-environment-variables-in-python?lq=1 – George Aug 23 '13 at 11:15

1 Answers1

0

You can write your variable and its value into an ini file from the python script.

In Values.ini file

my_var="value"

After executing python script, just invoke Values.ini using . operator

. Values.ini

Now your shell variable $my_var will be having the assigned value. The advantage with this method is that you can assign any number of variables like this.

var1="value1"

var2="value2"

var3="value3"

Antarus
  • 1,573
  • 2
  • 15
  • 32