James Stroud <js*****@mbi.ucla.eduwrote:
>stephen_b wrote:
>Can someone let me know why this won't work? Thanks.
>>>>>from os import popen
>popen('export asdfasdf=hello').read()
''
>>>>>popen('echo $asdfasdf').read()
'\n'
Python starts a new shell for each command, so your environment variable
is lost. You probably want this, which makes the variable "permanent".
pyimport os
pyos.environ['asdfasdf'] = 'hello'
pyos.popen('echo $asdfasdf').read()
'hello\n'
For completeness, let us anticipate the followup question and point out
that "permanent" here means "for this process and any processes that it
spawns". Once the Python session ends, the "asdfasdf" will be lost.
--
Tim Roberts,
ti**@probo.com
Providenza & Boekelheide, Inc.