# What file does the "in" operator reside in?

When I run something like

sage: 32 in ZZ
True


Where is this "in" operator defined? In general, is there a nice way to trace something like this to find the file(s) being accessed?

edit retag close merge delete

Sort by » oldest newest most voted

The in operator uses the Python special method __contains__. The Python documentation about this is here. You can get the source code for this by doing ZZ.__contains__??.

There is the trace function, but it isn't very useful for code in (compiled) Cython files unless you turn on profiling for Cython.

more

Thanks, is there any way to tell from the ?? output what file it is being defined in (as most other commands show)? As is, I grepped the files in the sage devel directory and came up with structure/parent.pyx and structure/parent.c files. Incidentally, should I be modifying pyx files or only their c counterparts?

( 2011-11-17 12:21:17 +0200 )edit

You can find the function source like this:

sage: ZZ.__contains__.__doc__
'File: sage/structure/parent.pyx (starting at line 950)...


and what object it belongs to with ZZ.__contains__.__objclass__ (and then you can do ZZ.__contains__.__objclass__??). I don't know if this will work generally.

Also, here are listed many operators with their corresponding names.

more

Thanks very much, that's very useful.

( 2011-11-17 15:21:02 +0200 )edit