equivalent of source <file> in python?
Thomas Jollans
thomas at jollybox.de
Tue Aug 24 16:36:00 EDT 2010
On Tuesday 24 August 2010, it occurred to News123 to exclaim:
> On 08/24/2010 09:18 PM, Astan Chee 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?
> > 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() )
Rather use execfile here.
Though you'd probably rather want to write a Python module and use it as such
(you know, import).
>
> but of course you had to translate /etc/setup
>
> to python.
More information about the Python-list
mailing list