2262Re: Bug in Vim' locales when calling Python script (?)
- Jan 6, 2007Bram Moolenaar wrote:
> Marijn wrote:You were correct. Thanks a million.
>> But the following script
>> # -*- coding: utf8 -*-
>> print unichr(40960)
>> In vim: "r !python test.py" gives the same: "'ascii' codec can't
>> encode character" error.
> The problem is in Python, this is a Python error message. This has
> nothing to do with Vim.
> I guess you somehow have to put Python in utf-8 mode first. This page
> appears to provide info: http://www.amk.ca/python/howto/unicode
>> Also:I added: "u.encode('utf-8')" and it worked flawlessly. After adding the same to my original code, that worked as well. I guess I didn't understand unicode too well after all... after reading you link everything felt in place. Python tried to pass unicode instead of utf8 strings. Sorry for the troubles, but thanks a lot.
>> def bar():
>> u = unichr(40960)
>> Still gives the "TypeError: bad argument type for built-in operation" error.
> Here "u" is of type "unicode", while the append() function requires a
> string. Perhaps Python has a function to convert type "unicode" to a
> string with utf-8 characters?
- << Previous post in topic