Re: TypeError: ord() expected a character, but string of length 3 found (Was: Updated python-uncertainties)
Andreas,
> > File "/usr/lib/python2.7/dist-packages/uncertainties/core.py", line 946, in <dictcomp>
> > ord(sup): normal for (normal, sup) in list(TO_SUPERSCRIPT.items())}
Please always provide a minimal testcase, otherwise people have to do a
lot of work simply to get where you are..
$ cat testcase.py
# coding=utf-8
TO_SUPERSCRIPT = {
0x2b: '⁺',
0x2d: '⁻',
0x30: '⁰',
0x31: '¹',
0x32: '²',
0x33: '³',
0x34: '⁴',
0x35: '⁵',
0x36: '⁶',
0x37: '⁷',
0x38: '⁸',
0x39: '⁹'
}
#! Python 2.7+ can use a dictionary comprehension instead:
FROM_SUPERSCRIPT = {
ord(sup): normal for (normal, sup) in list(TO_SUPERSCRIPT.items())}
$ python2 testcase.py
Traceback (most recent call last):
File "testcase.py", line 18, in <module>
ord(sup): normal for (normal, sup) in list(TO_SUPERSCRIPT.items())}
File "testcase.py", line 18, in <dictcomp>
ord(sup): normal for (normal, sup) in list(TO_SUPERSCRIPT.items())}
TypeError: ord() expected a character, but string of length 3 found
Under Python 2.x, list(TO_SUPERSCRIPT.items()) is:
[(43, '\xe2\x81\xba'),
(45, '\xe2\x81\xbb'),
(48, '\xe2\x81\xb0'),
[…]
]
ie. strings with a length of 3 whilst ord() takes a single char. These
should therefore be probably defined as:
TO_SUPERSCRIPT = {
0x2b: u'⁺',
0x2d: u'⁻',
[…]
.. instead, but I haven't tested or confirmed or anythinged that; I'll
leave it with you and upstream.
I also couldn't help notice:
Vcs-Browser: https://salsa.debian.org/debian/python-uncertainties
Vcs-Git: https://salsa.debian.org/debian/python-uncertainties.git
.. yet:
Maintainer: Debian Python Modules Team <python-modules-team@lists.alioth.debian.org>
Regards,
--
,''`.
: :' : Chris Lamb
`. `'` lamby@debian.org / chris-lamb.co.uk
`-
Reply to: