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

%history -g -f file encoding issue #1375

Closed
c000de opened this Issue Feb 4, 2012 · 3 comments

Comments

Projects
None yet
4 participants

c000de commented Feb 4, 2012

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!

Owner

fperez commented Feb 4, 2012

@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...

Owner

takluyver commented Feb 4, 2012

It's quite possibly still an issue in master - I'll look into it.

@takluyver takluyver added a commit to takluyver/ipython that referenced this issue Feb 4, 2012

@takluyver takluyver Fix for %hist saving non-ascii history to file.
Closes gh-1375
a66f7c9
Owner

takluyver commented Feb 4, 2012

See PR #1377

@minrk minrk closed this in fd42bee Feb 18, 2012

@yarikoptic yarikoptic pushed a commit to yarikoptic/ipython that referenced this issue May 2, 2014

@takluyver @minrk takluyver + minrk Fix for %hist saving non-ascii history to file.
Closes gh-1375
e9de8c7

@mattvonrocketstein mattvonrocketstein pushed a commit to mattvonrocketstein/ipython that referenced this issue Nov 3, 2014

@takluyver takluyver Fix for %hist saving non-ascii history to file.
Closes gh-1375
cb05179

@mattvonrocketstein mattvonrocketstein pushed a commit to mattvonrocketstein/ipython that referenced this issue Nov 3, 2014

@minrk minrk 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.

closes #1375
96ae4b6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment