[Tutor] ascii codec cannot encode character

Alex Hall mehgcap at gmail.com
Fri Jan 28 22:23:55 CET 2011


On 1/28/11, Dave Angel <davea at ieee.org> wrote:
> On 01/28/2011 08:02 AM, Alex Hall wrote:
>> On 1/28/11, Dave Angel<davea at ieee.org>  wrote:
>>> On 01/-10/-28163 02:59 PM, Alex Hall wrote:
>>>> <snip>
>>>> I tried both of those and got a different error. I have since fixed it
>>>> so I no longer have the exact text, but it was something about not
>>>> supporting convertion from unicode. I finally ended up doing this:
>>>> self.title�ta.find("title").text.encode("utf-8")
>>>> and it seems happy enough, though I get odd characters above 128. I
>>>> suppose it is better than a traceback, and I suspect I just have the
>>>> wrong character set. Still, I found it very odd that unicode(string,
>>>> errors=eplace') threw an exception.
>>>>>
>>>
>>> Well as I said before it would certainly have helped if you had quoted
>>> the entire error in the first place.  That includes the stack trace.
>>>
>>> But now that it's gone, you could answer some of the other questions.
>>>
>>> How are you using this  self.title value?  It's apparently a byte
>>> string, and you say it displays incorrectly.  But what device are you
>>> sending it to?  Your console on Windows, or your messagebox on wxPython?
>>>    Or where?
>> For the moment it will be a Win7x64 console or a .txt file on the same
>> machine (this is py2.7, but 2.6 is also installed). Eventually, as
>> this is an api wrapper, it will go to wx for me, and probably other
>> gui libraries if anyone else feels like using it.
>>>
>>> DaveA
>>>
>>
>>
> So clearly, the Win7x26 console on your machine doesn't support utf-8.
> As Peter said, you could inspect sys.stdout (that's what print uses) to
> see what encoding it specifies.
>
> Note that if you may be sending the data to various places, that may
> have different support, you probably don't want to encode it till it's
> know where it's going.  So you might leave self.title as unicode, but
> when you actually print it, encode it in the print statement.  And when
> you write it to a file, you encode it separately, and maybe differently.
>   And when you use it in wx, you pick a third way.
A great point. I have never had to deal with non-ascii before, so
never even thought about all this.
>
> Does anybody know what encodings the Win7x64 console can be made to
> support?  And how to tell what it's configured for, for a given country?
>
> DaveA
>


-- 
Have a great day,
Alex (msg sent from GMail website)
mehgcap at gmail.com; http://www.facebook.com/mehgcap


More information about the Tutor mailing list