Is there Python equivalent to Perl BEGIN{} block?
Carl Banks
pavlovevidence at gmail.com
Wed Mar 12 21:37:10 EDT 2008
On Mar 12, 8:11 pm, Justus Schwabedal <justus.schwabe... at gmx.de>
wrote:
> What do you need it for anyway? I just read about it and I think it's
> useless
> in python.
Perl, like Python, has a separate compilation and run times. One day,
someone who was trying to use Perl for something asked, "You know,
wouldn't it be neat-o if you could execute some Perl code *before* you
compiled the script?" And so (since that's usually enough reason to
add something to Perl) was borne the BEGIN block.
I believe the official rationale was that they wanted to add some
magic variables that affected Perl's compilation and couldn't do it
without a magic block that executed at compile time.
Python solved a similar problem by introducing __future__ imports.
Carl Banks
More information about the Python-list
mailing list