Is there Python equivalent to Perl BEGIN{} block?

Alex alex.pulver at gmail.com
Thu Mar 13 03:52:40 EDT 2008


On Mar 12, 8:48 pm, Carl Banks <pavlovevide... at gmail.com> wrote:
> On Mar 12, 2:19 pm, Alex <alex.pul... at gmail.com> wrote:
>
> > Hi all,
>
> > The subject says pretty much all, i would very appreciate an answer. I
> > tried to search the various forums and groups, but didn't find any
> > specific answer...
>
> Python technically has no equivalent: you can't run code at compile
> time.  However, the BEGIN block in Perl seems to have been added to
> work around some of Perl's nonlinear order of execution.  Normally in
> Python you don't need a BEGIN block: just put the code at the top of
> you script/module and it will exectute before anything else.
>
> Want to tell us what you need it for?  Perhaps we can suggest a way of
> doing it that's appropriate in Python.
>
> Carl Banks

Hi,

First of all thanks all for answering!

I have some environment check and setup in the beginning of the code.
I would like to move it to the end of the script. But I want it to
execute first, so the script will exit if the environment is not
configured properly.

Thanks,
Alex.



More information about the Python-list mailing list