Loading ...
Sorry, an error occurred while loading the content.

Re: Bug in Vim' locales when calling Python script (?)

Expand Messages
  • Marijn
    ... You were correct. Thanks a million. ... I added: u.encode( utf-8 ) and it worked flawlessly. After adding the same to my original code, that worked as
    Message 1 of 8 , Jan 6, 2007
    • 0 Attachment
      Bram Moolenaar wrote:
      > Marijn wrote:
      >
      >> But the following script
      >>
      >> ===========================
      >> #!/usr/bin/python
      >> # -*- 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
      >

      You were correct. Thanks a million.


      >> Also:
      >>
      >> ===========================
      >> def bar():
      >> u = unichr(40960)
      >> vim.current.buffer.append(u)
      >> ===========================
      >>
      >> 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?
      >

      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.


      Best regards,
      Marijn
    Your message has been successfully submitted and would be delivered to recipients shortly.