Is there a way that I can "unparse" one of the operators back into its textual form? For instance converting operator.__le__
to <=
. I know I can do that using if-then-else but I thought maybe there is a simpler way to do so.
Asked
Active
Viewed 23 times
0

JRR
- 6,014
- 6
- 39
- 59
-
2Perhaps a dict? `ops = {operator.__le__ : '<=', operator.__lt__: '<', ...}` – Nick Mar 22 '20 at 07:21
-
The closest you can do is something like `operator.add.__name__` which will give you `'add'`. For anything else you will have to create a mapping, kinda the inverse of [this question](https://stackoverflow.com/questions/1740726/turn-string-into-operator) – Tomerikoo Mar 22 '20 at 07:22