0

I want to run setenv command through python script, the linux command is as below

setenv MODEL path/to/the/model

I tried using os.environ(), but I couldn't get the right syntax.

note - I'm using python 2.7

manny
  • 338
  • 1
  • 11
  • 1
    By `setenv`, I suppose you're referring to the csh builtin. It's specific to `csh` and family. – William Pursell Mar 09 '20 at 16:15
  • Anything you run in a shell you start from Python only works *until that shell exits*; it won't change the environment of the Python interpreter, or the shell that started the Python interpreter. – Charles Duffy Mar 09 '20 at 16:33
  • @WilliamPursell, that's true, but even changing to use POSIX sh syntax, the command in question would still not have the desired effect. – Charles Duffy Mar 09 '20 at 16:35

1 Answers1

0

os.environ isn't a function. Check out the docs: https://docs.python.org/2/library/os.html#os.environ

This question may also be helpful to you: How to set environment variables in Python. If it is, pay attention to the comments on the top answer.

manny
  • 338
  • 1
  • 11
  • 1
    Duplicative questions should be closed, not answered. See the "Answer Well-Asked Questions" section of [How to Answer](https://stackoverflow.com/help/how-to-answer), particularly the bullet point regarding questions that "have already been asked and answered many times before". – Charles Duffy Mar 09 '20 at 16:34