4 ms·
An entire file is parsed first, before any code in it is run. If your __init__.py didn’t have any version-specific syntax, then yes you could check the interpr
by DecoPerson 4y ago
An entire file is parsed first, before any code in it is run.
If your __init__.py didn’t have any version-specific syntax, then yes you could check the interpreter version before importing the rest of the files.
- jwilk 4y agoOne minor benefit of a compile-time version check, is that when the check fails, you're not left with useless .pyc files. Besides, __init__.py doesn't always exist.
- klyrs 4y agoIf you're trying to make a version-robust module that won't attempt to compile a syntax error, top-level dispatch through __init__.py is an excellent approach.