Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find the definition of an operator in the python source code?

Tags:

python

I became curious about the implementation of the "in" (__contains__?) operator in python due to this SO question. I downloaded the source code and tried to grep, browse, etc. to find some base definition of it, but I haven't been successful. Could someone show me a way to find it?

Of course a general approach to finding that kind of thing would be best so anyone like me can learn to fish for next time.

I'm using 2.7 but if the process is totally different for 3.x, that would be nice to have both techniques.

like image 587
KobeJohn Avatar asked Feb 01 '12 01:02

KobeJohn


1 Answers

I think the implementation starts in PySequence_Contains in Objects/abstract.c. I found it by looking through the implementation of operator.contains in Modules/operator.c, which wraps all the native operators in Python functions.

like image 150
millimoose Avatar answered Nov 03 '22 20:11

millimoose