Ask Your Question
2

What file does the "in" operator reside in?

asked 2011-11-16 18:27:19 -0500

process91 gravatar image

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 flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
4

answered 2011-11-16 23:17:24 -0500

Mike Hansen gravatar image

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.

edit flag offensive delete link more

Comments

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?

process91 gravatar imageprocess91 ( 2011-11-17 05:21:17 -0500 )edit
1

answered 2011-11-17 07:25:21 -0500

parzan gravatar image

updated 2011-11-17 07:29:58 -0500

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.

edit flag offensive delete link more

Comments

Thanks very much, that's very useful.

process91 gravatar imageprocess91 ( 2011-11-17 08:21:02 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2011-11-16 18:27:19 -0500

Seen: 121 times

Last updated: Nov 17 '11