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
huyan3280
V2EX  ›  Python

Python 新手问题

  •  1
     
  •   huyan3280 · 2022-04-06 15:24:52 +08:00 · 2353 次点击
    这是一个创建于 744 天前的主题,其中的信息可能已经有所发展或是发生改变。

    windows 下 python 加了

    -- coding: utf-8 --

    还是报乱码,怎么解决,网上都是说加这个,但是没有效果呀!!

    9 条回复    2022-04-06 21:10:37 +08:00
    ALLROBOT
        1
    ALLROBOT  
       2022-04-06 15:28:35 +08:00
    zictos
        2
    zictos  
       2022-04-06 15:30:56 +08:00
    读文件的话在 windows 上要加 encoding=utf-8
    raycool
        3
    raycool  
       2022-04-06 15:32:17 +08:00
    问题太笼统,python2 还是 3 ?
    乱码具体指哪部分。
    huyan3280
        4
    huyan3280  
    OP
       2022-04-06 15:36:15 +08:00
    class Base(object):
    def __init__(self):
    self._age = 10

    def printInfo(self):
    print("age=%d,name = %s" % (self._age,self._name))

    class Child(Base):
    def __init__(self):
    super(Child,self).__init__()
    self._name = "这里是乱码"



    if __name__ == "__main__":
    child = Child()
    child.printInfo()
    fgwmlhdkkkw
        5
    fgwmlhdkkkw  
       2022-04-06 15:37:19 +08:00
    也有可能你把文件保存为 gbk 编码了
    v2exe2v
        6
    v2exe2v  
       2022-04-06 16:17:12 +08:00
    -- coding: gb-2312 --
    cmdOptionKana
        7
    cmdOptionKana  
       2022-04-06 16:23:29 +08:00
    1. 你的文件是自己新建的,还是网上下载的?
    2. 你使用什么编辑器?
    3. 你会查看文本文件的编码吗,你的这个文件是什么编码?
    deplivesb
        8
    deplivesb  
       2022-04-06 17:26:37 +08:00
    你这个不是 Python 新手,你是计算机新手
    imn1
        9
    imn1  
       2022-04-06 21:10:37 +08:00
    windows dos prompt 使用不是 utf 编码,它使用的字体也不支持跨字符集
    使用"chcp 65001"命令(不带引号),兼容 utf-8 输出,且更改字体为支持跨字符集的字体
    改字体这个需要一定的黑科技,请搜索相关文章(这个需要中文搜 google ,纯英文搜索没什么用)
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   893 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 21:16 · PVG 05:16 · LAX 14:16 · JFK 17:16
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.