Let's say I want to explore import
statements in Python. How, from the Python command line, can I find the file in which import
is defined? Note I am working in Python 2.7.6 (iPython) in Windows 7.
For most objects, just entering the object name is enough. For instance:
import os
os
Yields the following:
<module 'os' from 'C:\Anaconda\lib\os.pyc'>
But you cannot do the same with basic commands like import
.
I have tried searching my Python folder but unsurprisingly don't get something as simple as C:\Anaconda\lib\import.py
. Is there a simple way to find out where such statements are defined (I realize much of the time it will be in c-code, but that is what I am after)?
Update (5/27/14)
It seems people think it cannot be done in any simple way with a built-in command. However, if your life depended on it, you could write up some inelegant grep-type function in Python, no?
import
isn't amodule
the way thatos
is. Instead, it's astatement
.https://docs.python.org/2/reference/simple_stmts.html#import