Jun-04-2020, 03:09 AM
(This post was last modified: Jun-04-2020, 03:09 AM by Gribouillis.)
delahug Wrote:I then run into the problem above when using re.search() on the square bracket. It's caused (apparently) by the fraction in the first span.If you are running python 2.7, the problem is not caused by the fraction, it is caused by the implicit attempt to encode the string to the ascii encoding with the
str()
function, while the fraction character cannot be encoded with this encoding because it is not an ascii character. In python 3, there would be no such problem because str() doesnt try to encode the unicode string.>>> # python 2.7 >>> text = u"\xbd" >>> str(text) Traceback (most recent call last): File "<stdin>", line 1, in <module> UnicodeEncodeError: 'ascii' codec can't encode character u'\xbd' in position 0: ordinal not in range(128)You could perhaps try a unicode regex like
u"[[]"
and remove the call to str(), or better switch to python 3 because python 2 is no longer supported.