equivalent of source <file> in python?

Chris Rebert clp2 at rebertia.com
Tue Aug 24 16:28:42 EDT 2010


On Tue, Aug 24, 2010 at 12:18 PM, Astan Chee <astan.chee at al.com.au> wrote:
> Hi,
> I'm trying to convert my tcsh script to python and am stuck at one part,
> particularly the part of the script that looks like this:
>
> #!/bin/tcsh
> setenv LSFLOG /var/tmp/lsf_log
> source /etc/setup
> unalias cp
> umask 0
> env >> ${AFLOG}
>
> What is the equivalent of doing this in python2.5?

I agree with Stefan, but anyway, here's an approximate untested
literal translation:

import os
import subprocess

os.environ['LSFLOG'] = '/var/tmp/lsf_log'
subprocess.check_call(['tcsh', '/etc/setup'])
os.umask(0)
out = open(os.environ['AFLOG'], 'a')
subprocess.check_call(['env'], stdout=out)
out.close()

Cheers,
Chris
--
http://blog.rebertia.com



More information about the Python-list mailing list