0

I would like to execute a python file app.py like below:

python app.y

But I would like to pass to this file a new value = 'ok' for the env variable called 'training'.

How can I do this from shell with a single command?

1 Answers1

0

I think the approach should be a little different:

  1. set an environment variable: $ export training=ok
  2. inside your Python script, read the environment variable:
import os

print(os.getenv('training'))

Another option would be to use parameters and parse them with something like argparse.

pavelsaman
  • 7,399
  • 1
  • 14
  • 32
  • 2
    This has the potentially unwanted effects of permanently replacing any old value of the variable in the shell, and exposing it to all child processes. – tripleee Jan 04 '21 at 10:37