Score:0

Encoding Issues while running python through vim?

kr flag

I am currently facing a problem when executing :!python3 % in vim.

:!python3 test_glove.py
Traceback (most recent call last):
  File "test_glove.py", line 13, in <module>
    for line in f.readlines():
  File "/usr/lib/python3.6/encodings/ascii.py", line 26, in decode
    return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 1387: ordinal not in range(128)

A simple solution would be to directly tell the file handler which was the encoding of the file being read with open(GLOVE_FILENAME, "r+", encoding="utf-8") as f:.

But if the python3 compiler doesn't need to do that, why does vim require me to? Why can't vim !python3 operates just as python3 does?

This forces me to either define the encoding of every file I'm reading/writing or save and quit vim to compile and run it with python on the UNIX prompt, which yield no issues.

Is there any solutions for that? My ~/.vimrc encoding is set to utf-8 already.

set fileencodings=ucs-bom,utf-8,latin1
set encoding=utf-8

can someone explain to me what can be done?

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.