[IPython-User] writing ipython history to file, works in terminal, not in qtconsole and notebook

Mark Andrews andrews.markw@gmail....
Mon Sep 17 15:36:59 CDT 2012


Hi,
I am experiencing some strange errors writing ipython history to file.
In particular, I am able to write to file with ipython terminal, but
encounter a "TypeError: must be unicode, not str" error with the same
command in qtconsole and notebook.

I have googled for anyone experiencing something similar, but nothing
shows up. The error message seems to say that the filename should be
unicode, but doing so makes no difference.

I have pasted an example with the terminal and qtconsole below in the
hope that someone might have an insight.

thank you,
Mark

The terminal experience was as follows:

> ipython
Python 2.7.1+ (r271:86832, Apr 11 2011, 18:13:53)
Type "copyright", "credits" or "license" for more information.

IPython 0.13 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: x = 12

In [2]: %hist -f 'term_history'

In [3]: exit

# then at the linux shell, I have

> cat term_history
x = 12
%hist -f 'term_history'


# By contrast, the qtconsole experience was


Python 2.7.1+ (r271:86832, Apr 11 2011, 18:13:53)
Type "copyright", "credits" or "license" for more information.

IPython 0.13 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.
%guiref   -> A brief reference about the graphical user interface.

In [1]: x = 42

In [2]: %hist -f 'qtconsole_history'
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-2-05c52111e328> in <module>()
----> 1 get_ipython().magic(u"hist -f 'qtconsole_history'")

/usr/local/lib/python2.7/dist-packages/IPython/core/interactiveshell.pyc
in magic(self, arg_s)
   2159         magic_name, _, magic_arg_s = arg_s.partition(' ')
   2160         magic_name = magic_name.lstrip(prefilter.ESC_MAGIC)
-> 2161         return self.run_line_magic(magic_name, magic_arg_s)
   2162
   2163     #-------------------------------------------------------------------------

/usr/local/lib/python2.7/dist-packages/IPython/core/interactiveshell.pyc
in run_line_magic(self, magic_name, line)
   2085                 args.append(sys._getframe(stack_depth).f_locals)
   2086             with self.builtin_trap:
-> 2087                 result = fn(*args)
   2088             return result
   2089

<string> in hist(self, arg)

/usr/local/lib/python2.7/dist-packages/IPython/core/magic.pyc in
<lambda>(f, *a, **k)
    189     # but it's overkill for just that one bit of state.
    190     def magic_deco(arg):
--> 191         call = lambda f, *a, **k: f(*a, **k)
    192
    193         if callable(arg):

/usr/local/lib/python2.7/dist-packages/IPython/core/magics/history.pyc
in hist(self, arg)
    191     @line_magic
    192     def hist(self, arg):
--> 193         return self.history(arg)
    194
    195     hist.__doc__ = history.__doc__

<string> in history(self, parameter_s)

/usr/local/lib/python2.7/dist-packages/IPython/core/magic.pyc in
<lambda>(f, *a, **k)
    189     # but it's overkill for just that one bit of state.
    190     def magic_deco(arg):
--> 191         call = lambda f, *a, **k: f(*a, **k)
    192
    193         if callable(arg):

/usr/local/lib/python2.7/dist-packages/IPython/core/magics/history.pyc
in history(self, parameter_s)
    181                 if multiline:
    182                     inline = "\n...
".join(inline.splitlines()) + "\n..."
--> 183             print(inline, file=outfile)
    184             if get_output and output:
    185                 print(output, file=outfile)

TypeError: must be unicode, not str

# I have tried " %hist -f u'qtconsole_history' ", but no difference.


More information about the IPython-User mailing list