From b7d860b0fc731f06bd661ede0a4e880267157bdb 2021-07-08 20:07:11 From: Blazej Michalik Date: 2021-07-08 20:07:11 Subject: [PATCH] Print whole history on `%pycat` without parameters The only thing required here was removal of the empty argument guard, as `InteractiveShell.find_user_code` already understands empty string as "complete history of current session without the last line". --- diff --git a/IPython/core/magics/osm.py b/IPython/core/magics/osm.py index c2d3963..a904793 100644 --- a/IPython/core/magics/osm.py +++ b/IPython/core/magics/osm.py @@ -808,17 +808,17 @@ class OSMagics(Magics): This magic command can either take a local filename, an url, an history range (see %history) or a macro as argument :: + If no parameter is given, prints out history of current session up to + this point. + %pycat myscript.py %pycat 7-27 %pycat myMacro %pycat http://www.example.com/myscript.py """ - if not parameter_s: - raise UsageError('Missing filename, URL, input history range, ' - 'or macro.') - - try : - cont = self.shell.find_user_code(parameter_s, skip_encoding_cookie=False) + try: + cont = self.shell.find_user_code(parameter_s, + skip_encoding_cookie=False) except (ValueError, IOError): print("Error: no such file, variable, URL, history range or macro") return