[IPython-dev] Unicode bug in %whos, with patch
Fernando Perez
fperez.net at gmail.com
Sun Nov 25 01:08:00 EST 2007
On May 3, 2007 1:22 PM, Paul Mueller <gakusei at dakotacom.net> wrote:
> Hi,
>
> If you have a unicode variable with a character whose ordinal is >= 128, you
> get a UnicodeEncodeError on using %whos (this is using r2304):
>
> In [1]:u = u'\x80'
>
> In [2]:%whos
> Variable Type Data/Info
> -------------------------------
> u unicode ---------------------------------------------------------------------------
> <type 'exceptions.UnicodeEncodeError'> Traceback (most recent call last)
>
> /home/yuurei/src/mods/ipython/<ipython console> in <module>()
>
> /home/yuurei/src/mods/ipython/IPython/iplib.py in ipmagic(self, arg_s)
> 962 else:
> 963 magic_args = self.var_expand(magic_args,1)
> --> 964 return fn(magic_args)
> 965
> 966 def ipalias(self,arg_s):
>
> /home/yuurei/src/mods/ipython/IPython/Magic.py in magic_whos(self, parameter_s)
> 1057 print '(%s Mb)' % (vbytes/Mb,)
> 1058 else:
> -> 1059 vstr = str(var).replace('\n','\\n')
> 1060 if len(vstr) < 50:
> 1061 print vstr
>
> <type 'exceptions.UnicodeEncodeError'>: 'ascii' codec can't encode character u'\x80' in position 0: ordinal not in range(128)
>
>
> I've attached a patch that fixes this.
Thanks again, Paul, things are now OK for the upcoming release:
In [1]: u = u'\x80'
In [2]: %whos
Variable Type Data/Info
-------------------------------
u unicode \x80
In [3]:
Sorry again for the ridiculous delay in dealing with your
contributions. That's no way to treat your users, esp. those who
pitch in with patches! Mea culpa.
Cheers,
f
More information about the IPython-dev
mailing list