Python script output with broken pipe error

I am trying to get the source code of a python script. that is, I would like to be able to run:

$ source <(python example.py)

It ALWAYS fails with the same problem:

Exception ignored in: <_io.TextIOWrapper name='<stdout>' mode='w' encoding='UTF-8'>
BrokenPipeError: [Errno 32] Broken pipe

Here is an .py example:

print("export ENV_VAR=abc")

Is there any way around this? I tried to try the exception (BrokenPipeError), but it does not seem to work. The exception seems to prevent the source from working with

$ echo $ENV_VAR

gives nothing

+4
source share
1 answer

Maybe, evalor exportcan be used to get variables from a Pythonscript into the current environment Bash:

export $( python example.py )
echo $ENV_VAR

... or...

eval $( python example.py )
echo $ENV_VAR

There may be a better way to handle this, although both should output "abc".

+1
source

Source: https://habr.com/ru/post/1691126/


All Articles