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
  • 16,954
  • 15
  • 107
  • 126

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
  • 963,270
  • 265
  • 3,804
  • 3,187