GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
Already on GitHub? Sign in to your account
When I tried to write my entire IPython history to a file using the %hist magic function, I get an encoding error:
/usr/local/lib/python2.6/dist-packages/ipython-0.11-py2.6.egg/IPython/core/history.pyc in magic_history(self, parameter_s)
685 if multiline:
686 inline = "\n... ".join(inline.splitlines()) + "\n..."
--> 687 print(inline, file=outfile)
688 if get_output and output:
689 print(output, file=outfile)
UnicodeEncodeError: 'ascii' codec can't encode character u'\u2014' in position 3929: ordinal not in range(128)
If you'd append line 676 to include an encoding to (say) UTF-8:
inline = inline.expandtabs(4).rstrip().encode('utf8')
That would fix the issue. Hope this helps, and thanks for making IPython as awesome as it is!
@takluyver, do you think this is still an issue in master? If so, it would be good to put in a failing test before we make any attempt at fixing it...
It's quite possibly still an issue in master - I'll look into it.
Fix for %hist saving non-ascii history to file.
See PR #1377
Merge pull request #1377 from takluyver/i1375
Non ascii history caused problems for the %hist command with the -f option to save to file. This adds a test and fixes it using io.open.