Python Forum

Full Version: setting evironment of Linux using python
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi I am trying to convert a shell script to python. In shell script they are setting the Environment I don't know how to do that using the python here is the sample from the shell script.

# set the test Environment
SAM_HOME=/opt/test
[ -f "~sam/bin/testenv" ] && SAM_HOME=~sam
. $SAM_HOME/bin/testenv
. $SAM_HOME/bin/session
Hi, I don't know the exact answer to your question, but would it be fine to execute your existing shell script with Python's "os" module?
http://www.pythonforbeginners.com/os/pythons-os-module
Particularly the "os.system()" method:
https://docs.python.org/3/library/os.html#os.system
hi, I am trying it in python in this way

# set the test Environment
SAM_HOME = "/opt/test"


if os.path.exists("~sam/bin/test"):
SAM_HOME = "~sam"
os.system(". " + SAM_HOME + "/bin/test")
os.system(". " + SAM_HOME + "/bin/session")