diff --git a/IPython/core/magics/history.py b/IPython/core/magics/history.py index 6dcc768..c21fa2f 100644 --- a/IPython/core/magics/history.py +++ b/IPython/core/magics/history.py @@ -24,6 +24,7 @@ from IPython.core.magic_arguments import (argument, magic_arguments, parse_argstring) from IPython.testing.skipdoctest import skip_doctest from IPython.utils import io +from IPython.utils.py3compat import cast_unicode_py2 #----------------------------------------------------------------------------- # Magics class implementation @@ -213,7 +214,7 @@ class HistoryMagics(Magics): inline = "\n... ".join(inline.splitlines()) + "\n..." print(inline, file=outfile) if get_output and output: - print(output, file=outfile) + print(cast_unicode_py2(output), file=outfile) if close_at_end: outfile.close() diff --git a/IPython/core/tests/test_magic.py b/IPython/core/tests/test_magic.py index 3e583ad..89f46df 100644 --- a/IPython/core/tests/test_magic.py +++ b/IPython/core/tests/test_magic.py @@ -236,6 +236,16 @@ def doctest_hist_op(): >>> """ +def test_hist_pof(): + ip = get_ipython() + ip.run_cell(u"1+2", store_history=True) + #raise Exception(ip.history_manager.session_number) + #raise Exception(list(ip.history_manager._get_range_session())) + with TemporaryDirectory() as td: + tf = os.path.join(td, 'hist.py') + ip.run_line_magic('history', '-pof %s' % tf) + assert os.path.isfile(tf) + @dec.skip_without('sqlite3') def test_macro():