[IPython-dev] Python 3 on Windows

Thomas Kluyver takowl at gmail.com
Thu Feb 2 11:25:41 EST 2012

On 2 February 2012 16:12, Daniel Griffith <daniel.dang.griffith at gmail.com>wrote:

> I ran "a = !ls" and tried to "print(a.nlstr)" to see the results, and it
> complained about having bytes instead of strings:
> "TypeError: sequence item 0: expected str instance, bytes found".
> The earlier stage would be in the "!" handler; I haven't looked at that
> code. I assume there are reasons it is putting
> bytes into the SList instead of strings. Maybe it should change instead? I
> don't know. I suppose that would depend
> on whether other code will assume that SList contains only strings and
> whether "!" is returning bytes.

That's the stage I'd look at - the code starts with the getoutput method

The trouble with just calling str is that it doesn't always do what you
might expect, so if we've got bytes, it's better to decode them:

>>> str(b'abc')
>>> b'abc'.decode()  # ...but we need to work out the encoding

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ipython-dev/attachments/20120202/37d976fb/attachment.html>

More information about the IPython-dev mailing list