Is there Python equivalent to Perl BEGIN{} block?

Jeff Schwab jeff at
Thu Mar 13 05:33:52 CET 2008

Alex wrote:

> 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...

I'd like an answer to this, too.  In Perl, I mostly used it for 
one-liners, when a variable needed to be initialized to some non-default 
value; for example, perl -ple 'BEGIN { $sum = 42 } $sum += $_'.

More information about the Python-list mailing list