Idiom for running compiled python scripts?

irstas at gmail.com irstas at gmail.com
Sun Mar 25 04:36:12 EDT 2007


On Mar 25, 2:46 am, Mark <m... at mailinator.com> wrote:
> On Sat, 24 Mar 2007 07:21:21 -0700, irstas wrote:
> > A simple implementation that "works":
>
> Not quite irstas BTW ..

I was expecting this, hence the quotes around 'works' :P.
Another known issue is that globals() dictionary is somewhat
different when ran with my module. You should probably
look into the runpy's source code for better environment
compability (Python25/Lib/runpy.py). Although no quarantees
that it'd help.

> Something about the environment is not quite the same. Any ideas?

What Gabriel said may be the correct fix (I actually couldn't
reproduce the
bug so I couldn't test), but here's another idea: You could wrap
your main method in a try-finally block:

def main():
    try:
        do things
    finally:
        remove temp files

The finally-block will be executed even if you call sys.exit
inside the try-block. This change will also make it possible
to invoke your script many times, with temp files getting deleted
after each invocation, should this ever be useful to you.
(well, not if you use sys.exit :P)




More information about the Python-list mailing list