How to use export with Python on Linux

后端 未结 12 1549
梦如初夏
梦如初夏 2020-11-29 23:09

I need to make an export like this in Python :

# export MY_DATA=\"my_export\"

I\'ve tried to do :

# -*- python-mode -*-
# -         


        
12条回答
  •  旧时难觅i
    2020-11-29 23:18

    Another way to do this, if you're in a hurry and don't mind the hacky-aftertaste, is to execute the output of the python script in your bash environment and print out the commands to execute setting the environment in python. Not ideal but it can get the job done in a pinch. It's not very portable across shells, so YMMV.

    $(python -c 'print "export MY_DATA=my_export"')
    

    (you can also enclose the statement in backticks in some shells ``)

提交回复
热议问题