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='')
| 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( |
nothing calls this directly
no test coverage detected