MCPcopy Create free account
hub / github.com/ipython/ipython / pycat

Method pycat

IPython/core/magics/osm.py:799–823  ·  view source on GitHub ↗

Show a syntax-highlighted file through a pager. This magic is similar to the cat utility, but it will assume the file to be Python source and will show it with syntax highlighting. This magic command can either take a local filename, an url, an history range (see %h

(self, parameter_s='')

Source from the content-addressed store, hash-verified

797
798 @line_magic
799 def pycat(self, parameter_s=''):
800 """Show a syntax-highlighted file through a pager.
801
802 This magic is similar to the cat utility, but it will assume the file
803 to be Python source and will show it with syntax highlighting.
804
805 This magic command can either take a local filename, an url,
806 an history range (see %history) or a macro as argument ::
807
808 %pycat myscript.py
809 %pycat 7-27
810 %pycat myMacro
811 %pycat http://www.example.com/myscript.py
812 """
813 if not parameter_s:
814 raise UsageError('Missing filename, URL, input history range, '
815 'or macro.')
816
817 try :
818 cont = self.shell.find_user_code(parameter_s, skip_encoding_cookie=False)
819 except (ValueError, IOError):
820 print("Error: no such file, variable, URL, history range or macro")
821 return
822
823 page.page(self.shell.pycolorize(source_to_unicode(cont)))
824
825 @magic_arguments.magic_arguments()
826 @magic_arguments.argument(

Callers

nothing calls this directly

Calls 4

UsageErrorClass · 0.90
source_to_unicodeFunction · 0.90
find_user_codeMethod · 0.80
pageMethod · 0.80

Tested by

no test coverage detected