1

I have a bash script and a python script:

script

#!/bin/bash
a=10
export a
python script.py

script.py

# access 'a' somehow

Is there a way to access the exported variables from python?

Pithikos
  • 18,827
  • 15
  • 113
  • 136

1 Answers1

3

Exported variables are set as environment variables. Use os.environ (a dictionary) to read these in your Python script:

import os

a = os.environ['a']
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343