4 ms·
This is a good point, but can’t you do it in __init__.py? I thought that ran first
by klysm 4y ago
This is a good point, but can’t you do it in __init__.py? I thought that ran first
- DecoPerson 4y agoAn 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.