4 ms·
Interesting. Is there a way to do something like this in Python?
by Fiahil 10y ago
Interesting. Is there a way to do something like this in Python?
- xapata 10y agoYes. You can get pretty fancy with decorators, and there's always eval/exec if you need it. The stdlib has plenty of power tools for introspection. The leg up that lisps have over Python is that Python's eval/exec operates on strings whereas lisps can easily manipulate the AST. (I'm not sure if I should call it abstract for a lisp.) Directly manipulating Python's AST can be done with the aptly named ast module, but personally I find it easier to do string templating and eval.