4 ms·
The `codecs.register` approach is interesting. I hope Ruby has something similar. Unfortunately I could not find such thing in Ruby.
by b6fan 11y ago
The `codecs.register` approach is interesting. I hope Ruby has something similar. Unfortunately I could not find such thing in Ruby.
- est 11y agoYup that's the point of my submission, too bad HN edited my title so it looks like a boring trick. It allows you to transform your code without significant speed loss. Think of possibilities like # coding: JIT or # coding: inline-C etc.
- maxerickson 11y agoThe typical way to do that is to reuse the interpreter infrastructure. This hack could be done with the ast: https://docs.python.org/3.5/library/ast.html#ast.NodeTransformer https://docs.python.org/3.5/library/ast.html#ast.NodeTransfo...
- est 11y agoAST is cool, but you have to comply with Python's syntax. the coding way you can invent any wild syntax.
- maxerickson 11y agoI guess my first approach to that would not involve overloading the import statement.