Skip to content
This repository

%run does not work with non-ascii characeters in path #818

Closed
jstenar opened this Issue September 22, 2011 · 10 comments

4 participants

Jörgen Stenarson Thomas Kluyver Min RK Fernando Perez
Jörgen Stenarson
Collaborator

When I try to %run a script when there are non-ascii characters in the path I get unicode decode errors.

In [4]: %run scriptåäö.py
---------------------------------------------------------------------------
UnicodeEncodeError                        Traceback (most recent call last)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 35-37: ordinal not in range(128)

As far as I can tell the problem is that execfile does not tolerate non-ascii characters in the path.
I have a fix implemented in my execfile branch where I have switched to using exec and compile instead.

/Jörgen

Min RK
Owner

It might make sense to just encode unicode filenames with sys.getfilesystemencoding() before passing to execfile.

Jörgen Stenarson
Collaborator
Min RK
Owner

Why would a mixture of Greek and Latin make a difference? I can (and do) have Greek, Latin, and Japanese filenames on my system, all of which are encoded with the filesystem encoding, and work just fine with execfile.

Does Windows have different encodings associated on a per-file basis?

Jörgen Stenarson
Collaborator
Fernando Perez
Owner

@jstenar, what's your take on this then moving forward? If the approach suggested by @minrk isnt' enough on win32, then we may need to go with yours. Keep in mind we have a function called safe_execfile() that we make all our execfile calls through. That would be the right point to put more layers of safety in.

And if the more manual approach you describe is truly necessary on win32, we can just do it conditionally: use the simpler method Min suggested in general, but specialize to you manual method on win32.

If that sounds reasonable, feel free to whip up a PR for it. The window before 0.12 is closing though... I'd like to try to close as many of the open PRs as possible and start freezing for beta testing and stabilization.

Jörgen Stenarson jstenar referenced this issue October 18, 2011
Merged

Execfile #896

Jörgen Stenarson
Collaborator

I created PR #896

I think it makes more sense to put it in the py3compat module because otherwise I will have to put py3 related logic in safe_execfile as well which seems awkward to me.

Do you have any ideas on how to test this? safe_execfile is supposed to swallow all exceptions so how do I check for my error case?

/Jörgen

Fernando Perez
Owner
Jörgen Stenarson
Collaborator
Thomas Kluyver
Collaborator

@jstenar: The PR relating to this is merged now - can we close this issue?

Jörgen Stenarson
Collaborator
Thomas Kluyver takluyver closed this October 20, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.