Is there Python equivalent to Perl BEGIN{} block?

Carl Banks pavlovevidence at gmail.com
Wed Mar 12 14:48:20 EDT 2008


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



More information about the Python-list mailing list