V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
Anhedonia
V2EX  ›  Python

VSC 写 Python 出现了编码问题

  •  
  •   Anhedonia · 2017-02-26 17:06:10 +08:00 · 3441 次点击
    这是一个创建于 2606 天前的主题,其中的信息可能已经有所发展或是发生改变。

    用 coderunner 插件运行 Python 文件

    UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-3: ordinal not in range(128) 报错提示这个

    问题是我已经在文件最上面加了

    -- coding: utf-8 --

    而且 vsc 的设置里 files.encoding": "utf8", 也设置好了

    这是为什么呢?

    6 条回复    2017-02-27 09:33:44 +08:00
    formulahendry
        1
    formulahendry  
       2017-02-26 17:51:35 +08:00 via Android   ❤️ 1
    你好,我是插件作者。你 py 文件内容是啥,里面有中文?可以试试这里面的三种解决方案: https://github.com/formulahendry/vscode-code-runner/issues/25
    Anhedonia
        2
    Anhedonia  
    OP
       2017-02-26 22:32:23 +08:00
    @formulahendry 好啦好啦!!谢谢谢谢!!!!顺便一提 你的插件好棒的!
    formulahendry
        3
    formulahendry  
       2017-02-26 23:01:13 +08:00 via Android
    @Anhedonia 😀
    kevin100702
        4
    kevin100702  
       2017-02-26 23:45:00 +08:00 via Android
    Import Io
    Io.set …………
    原谅我不会手机打代码
    WildCat
        5
    WildCat  
       2017-02-26 23:59:16 +08:00 via iPhone
    @formulahendry 全球第一工单论坛 😂
    suixn
        6
    suixn  
       2017-02-27 09:33:44 +08:00
    ···
    import io
    sys.stdout = io.TextIOWrapper(sys.stdout.buffer,encoding='utf8')
    ···
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1004 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 22:16 · PVG 06:16 · LAX 15:16 · JFK 18:16
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.