Interactive os.environ vs. os.environ in script

boris.smirnov at gmail.com boris.smirnov at gmail.com
Tue Feb 27 04:47:00 EST 2007


On Feb 27, 10:33 am, Peter Otten <__pete... at web.de> wrote:
> boris.smir... at gmail.com wrote:
> > On Feb 27, 9:31 am, Peter Otten <__pete... at web.de> wrote:
> >> boris.smir... at gmail.com wrote:
> >> > Is there another possibility of how to solve it just by adding some
> >> > lines in script?
>
> >> I think you have to wrap your script in a shell script
>
> >> #!/bin/sh
> >> export LD_LIBRARY_PATH=/path/Linux/rh_linux
> >> python shrink_bs_070226.py
>
> >> To avoid that you can have the python script invoke itself, e. g.:
>
> >> #!/usr/bin/env python
> >> import os
> >> if os.environ.get("YADDA") != "whatever":
> >>     print "fix environment"
> >>     os.environ["YADDA"] = "whatever"
> >>     os.system("yadda.py")
> >>     raise SystemExit
>
> >> print "YADDA is now %r" % os.environ["YADDA"]
> >> print "do your real stuff"
>
> >> Peter
>
> > Thanks for the reply.
>
> > If I that good understood I did this:
> > **********************************
> > import sys, re, glob, shutil
> > import os
>
> > if os.environ["LD_LIBRARY_PATH"].count('/path/Linux/rh_linux') !=1:
> >    os.environ["LD_LIBRARY_PATH"]=os.environ["LD_LIBRARY_PATH"]+':'+'/
> > path/Linux/rh_linux'
> >    os.system("shrink_bs_070226.py")
> >    raise SystemExit
>
> > from qt import *
> > ***********************
>
> > Is that correct. If yes then it not works. If not then, what's wrong?
>
> I don't know. You are not quoting the actual code you are using (from qt
> import * is definitely not in line 29, and the #!/path/to/your/python is
> missing). Do you have more than one python version installed? then you may
> have to put
>
> #!/usr/bin/python2.2
>
> or similar in the first line of your script.
>
> Peter- Hide quoted text -
>
> - Show quoted text -

Probably I understood it not correctly. What did you mean was to put
that code into my python script "shrink_bs_070226.py" and then calls
script itself?

So I took my script "shrink_bs_070226.py" and it starts with:
**********************************
#!/usr/bin/env python
import sys, re, glob, shutil
import os

then I put your code in that script

if os.environ["LD_LIBRARY_PATH"].count('/path/Linux/rh_linux') !=1:
   os.environ["LD_LIBRARY_PATH"]=os.environ["LD_LIBRARY_PATH"]+':'+'/
path/Linux/rh_linux'
   os.system("shrink_bs_070226.py")
   raise SystemExit

and here continues my script:

from qt import *

.....
***********************

Is it correct?

BTW: On lines 3:18 I have comments, script description and
modifications, therefore is "from qt import *" on the line 29






More information about the Python-list mailing list