How to use export with Python on Linux

后端 未结 12 1531
梦如初夏
梦如初夏 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条回答
  •  既然无缘
    2020-11-29 23:35

    I've had to do something similar on a CI system recently. My options were to do it entirely in bash (yikes) or use a language like python which would have made programming the logic much simpler.

    My workaround was to do the programming in python and write the results to a file. Then use bash to export the results.

    For example:

    # do calculations in python
    with open("./my_export", "w") as f:
        f.write(your_results)
    
    # then in bash
    export MY_DATA="$(cat ./my_export)"
    rm ./my_export  # if no longer needed
    

提交回复
热议问题