Is there Python equivalent to Perl BEGIN{} block?
Paddy
paddy3118 at googlemail.com
Thu Mar 13 01:09:48 EDT 2008
On Mar 13, 1:37 am, Carl Banks <pavlovevide... at gmail.com> wrote:
> 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
And theres me thinking it was part of Perls AWK compatibility code.
- Paddy.
More information about the Python-list
mailing list