←back to thread

160 points leontrolski | 2 comments | | HN request time: 0.399s | source
Show context
Y_Y ◴[] No.41887424[source]
If only there was a language that let you modify the interpreter on the fly so you could do this as part of normal execution...
replies(4): >>41887458 #>>41887499 #>>41887640 #>>41888996 #
BiteCode_dev ◴[] No.41887458[source]
Python can actually do this using "# coding:", albeit less elegantly than lisp.

I would say it's a good thing, I don't want to see a hundred of half baked, badly tested and vaguely document DSL with no decent tooling support.

replies(2): >>41887507 #>>41887939 #
develatio ◴[] No.41887507[source]
Can you provide some more info / links regarding the “# coding:” feature? I wasn’t able to find anything.
replies(4): >>41887621 #>>41887770 #>>41887778 #>>41887841 #
1. JackC ◴[] No.41887778[source]
The idea is you can register a custom file encoding, analogous to built-in file encodings like utf-8, and use it to transform the source file before python loads it. An example is pyxl, kind of like jsx, where you put `# coding: pyxl` at the top and then it will transform bare `<html>` in the python file into calls to a template builder: https://github.com/gvanrossum/pyxl3

Incidentally this turns out to be super hard to search for without asking an LLM, since "python coding" is so overloaded, and using the feature this way is intentionally undocumented because it's not really what it's for, and not something I think most python users really want to encourage. So, forbidden python knowledge!

replies(1): >>41887802 #
2. kevindamm ◴[] No.41887802[source]
It's specified in PEP 263 [0] which pulls up easier on search if you quote it and include the typical "special comment symbol" -*- around it.

[0]: https://peps.python.org/pep-0263/