First time here? Check out the FAQ!

Ask Your Question
2

What file does the "in" operator reside in?

asked 13 years ago

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?

Preview: (hide)

2 Answers

Sort by » oldest newest most voted
4

answered 13 years ago

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.

Preview: (hide)
link

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 ( 13 years ago )
1

answered 13 years ago

parzan gravatar image

updated 13 years ago

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.

Preview: (hide)
link

Comments

Thanks very much, that's very useful.

process91 gravatar imageprocess91 ( 13 years ago )

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: 13 years ago

Seen: 405 times

Last updated: Nov 17 '11