Comment

Comment by tyingq

I wish Python had come with some equivalent to the "BEGIN {}" blocks that Perl and Awk have.

Lacking that, there's no way to write a (single file) script where a Python 2 interpreter would just get a "You need Python 3" error instead of a syntax error. Because testing for the interpreter version happens too late...after the syntax error already happened.

Perl's "BEGIN {}" block lets you easily test for versions or language features before the script itself is parsed.

parent tyingq 5 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton