New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add encoding
attribute to OutStream
class.
#2500
Conversation
I wonder if explicitly setting UTF-8 makes more sense than using |
Yeah, I have no idea. In write we do use But this is a completely backwards usage in some sense, as in a regular file object, Since we never encode the text (and instead just keep it with type |
My use-case is defining a In py2.x repr() must return a str() not unicode(). With the current implementation of I think |
Hmm, but I suspect
|
True, although if a character is not supported, then it won't display correctly |
But the Qt console and the notebook don't have to rely on Windows' character set - both should be able to display arbitrary unicode characters. |
For the following reasons, I suggest that we close this issue and mark #2220 as invalid.
|
On the other hand io.TextIOBase.encoding should always exist in Python 3. In that case, we just want to choose something so that |
You just wouldn't want a situtation where sys.stdout.encoding (specifying what if that's not a possibility, so much the better. |
that would be a problem, since sys.getdefaultencoding() returns |
'utf-8' is good, I just can't the bit of code that explicitly states that qt and nb always use utf-8 and nothing but. |
I have access to a windows machine, would gladly test whatever you'd like. |
It's rather confusing: when you encode something to utf-8 to return from |
what's confusing about that? :) |
Perhaps 'convoluted' would be a better word ;-) |
This means that `sys.stdout.encoding` returns something useful instead of raising an AttributeError. 'UTF-8' was chosen because our version of write actually wants a unicode string (i.e., not `bytes`) and we want something universal which an encode the entire range of unicode characters.
@takluyver & @y-p I think this is what you both were suggesting... Let's give this a thorough test in Windows now. |
Will do. |
Test suite passes on 2.7 on win7 (no errors beyond those of current git master) and this works for me, using qtconsole import sys
class A():
def __repr__(self):
return u"שלום".encode(sys.stdout.encoding)
A()
שלום as a sidenote, settting up for tests was pretty painful. no CI server? |
and of course:
|
As usual, Windows is dramatically more painful than other platforms, principally because there are no IPython devs who use it. That said, I have found that And we do have two CI environments running. Travis automatically runs all PRs (as seen in the 'Good to merge' notes on this and every PR), and we also have ShiningPanda, which recently started Windows tests (again, much more painful to do CI on Windows than other platforms). |
@minrk, python, then setuptools (from web), then pip (that's what I use on linux),then nose, then setup.py develop, then all the deps by hand, then back to easy_install because some deps where egg-only, and then more binaries from |
replicating the tests in #529: In [7]: print u"åäö".encode('utf-8')
åäö
In [8]: print u"åäö"
åäö
In [5]: "åäö"
Out[5]: '\xc3\xa5\xc3\xa4\xc3\xb6' for completeness In [2]: u"åäö".encode("utf-8").decode("cp850")
Out[2]: u'\u251c\xd1\u251c\xf1\u251c\xc2'
In [3]: print u"åäö".encode("utf-8").decode("cp850")
├Ñ├ñ├Â
In [4]: print u"åäö".encode('cp850')
���
In [6]: print u"åäö".encode('cp1252')
��� where � is the unicode replacement symbol, which windows mangles for some reason, but |
@y-p : Could you also test in the qtconsole Our Windows CI runs are currently failing, unfortunately. If you've got spare time, could you test #2478, which should address the test failure. |
In notebook. In [16]: print "שלוםåäö"
שלוםåäö In qtconsole, the display is right aligned because it begins with RTL script, |
OK, then I think this is all OK. @bfroehle , anything else you want to check? If not, let's land this. |
Okay, hope it doesn't break anything! :) Merging now. |
Add `encoding` attribute to `OutStream` class.
This means that `sys.stdout.encoding` returns something useful instead of raising an AttributeError. Closes #2220.
when redirected to a file stdout is None, in ipython zmq frontends stdin is None, and stdout (only recently in 0.14) is utf-8. ipython/ipython#2500
Add `encoding` attribute to `OutStream` class.
This means that
sys.stdout.encoding
returns something useful instead of raising an AttributeError.Closes #2220.