开发者

Overwriting default behavior for python operators

I know that to alter the default开发者_StackOverflow中文版 behavior of operators in python you can override some default methods like __add__ or __sub__ for + and -, but didn't find anything to override the behavior of the and and or keywords, while there are some for the bitwise operators &, |: respectively __and__ and __or__.

Do you know if there are hooks for these keywords also? I know it's strange to override the default behavior of and & or, but I need this to construct an abstract syntax tree starting from a python formula at runtime, don't really want to alter its semantics in a weird way.

If not, I would like to modify the language itself to have this support. If there's some good expert that could suggest me the right way to do so please put your hands up, otherwise I think I'll ask Guido for that :)

Thanks a lot floks!


is, and, and or cannot be overloaded. Use the Python language services if you want to write a Pythonesque DSL.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜