3 ms·
There's an interesting extensibility point in Python in form of codecs and the encoding comment: # -*- coding: ... -*- The trick is that encoding names com
by int_19h 5y ago
There's an interesting extensibility point in Python in form of codecs and the encoding comment:
# -*- coding: ... -*-
The trick is that encoding names come from an extensible registry of codecs (https://docs.python.org/3/library/codecs.html#codecs.register https://docs.python.org/3/library/codecs.html#codecs.registe...), so you can register your own. And when you look at codec API, you get the raw byte stream as input, and spit out strings - so it's basically as powerful as reader macros.
The problem is getting that registration code to run before your script starts. Easy if you have multiple scripts, but it requires .pth hacks if you go for single-file.