equivalent of source <file> in python?

A

Astan Chee

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?
Thanks again
 
N

News123

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?
Thanks again

the equivalent would be exec(), but I'm not sure, that it is a good idea
to try to make a
word by word translation of a shell script into python.


you could do
exec( open("/etc/setup").read() )

but of course you had to translate /etc/setup

to python.
 
S

Stefan Schwarzer

Hi Astan,

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 guess it doesn't make sense to "translate" this to Python
line by line. For example, you can't "source" shell code
into a Python program. The above commands don't look as if
they were the purpose of the program, but rather mostly some
preparation/setup before solving the actual problem.

Maybe it's more helpful to tell us what you want to achieve
in the end and we might be able to make suggestions on that.

How long is the shell script and what's your Python code so
far?

Stefan
 
T

Thomas Jollans

the equivalent would be exec(), but I'm not sure, that it is a good idea
to try to make a
word by word translation of a shell script into python.


you could do
exec( open("/etc/setup").read() )

Rather use execfile here.

Though you'd probably rather want to write a Python module and use it as such
(you know, import).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top