MCPcopy Index your code
hub / github.com/ipython/ipython / pfile

Method pfile

IPython/core/magics/namespace.py:101–122  ·  view source on GitHub ↗

Print (or run through pager) the file where an object is defined. The file opens at the line where the object definition begins. IPython will honor the environment variable PAGER if set, and otherwise will do its best to print the file in a convenient form. If the g

(self, parameter_s='', namespaces=None)

Source from the content-addressed store, hash-verified

99
100 @line_magic
101 def pfile(self, parameter_s='', namespaces=None):
102 """Print (or run through pager) the file where an object is defined.
103
104 The file opens at the line where the object definition begins. IPython
105 will honor the environment variable PAGER if set, and otherwise will
106 do its best to print the file in a convenient form.
107
108 If the given argument is not an object currently defined, IPython will
109 try to interpret it as a filename (automatically adding a .py extension
110 if needed). You can thus use %pfile as a syntax highlighting code
111 viewer."""
112
113 # first interpret argument as an object name
114 out = self.shell._inspect('pfile',parameter_s, namespaces)
115 # if not, try the input as a filename
116 if out == 'not found':
117 try:
118 filename = get_py_filename(parameter_s)
119 except IOError as msg:
120 print(msg)
121 return
122 page.page(self.shell.pycolorize(read_py_file(filename, skip_encoding_cookie=False)))
123
124 @line_magic
125 def psearch(self, parameter_s=''):

Callers

nothing calls this directly

Calls 4

get_py_filenameFunction · 0.90
read_py_fileFunction · 0.90
_inspectMethod · 0.80
pageMethod · 0.80

Tested by

no test coverage detected