推荐学习书目
› 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 · Apr 6, 2022 · 3616 views
    This topic created in 1635 days ago, the information mentioned may be changed or developed.

    windows 下 python 加了

    -- coding: utf-8 --

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

    9 replies  •  2022-04-06 21:10:37 +08:00
    ALLROBOT
        1
    ALLROBOT  
       Apr 6, 2022
    zictos
        2
    zictos  
       Apr 6, 2022
    读文件的话在 windows 上要加 encoding=utf-8
    raycool
        3
    raycool  
       Apr 6, 2022
    问题太笼统,python2 还是 3 ?
    乱码具体指哪部分。
    huyan3280
        4
    huyan3280  
    OP
       Apr 6, 2022
    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  
       Apr 6, 2022
    也有可能你把文件保存为 gbk 编码了
    v2exe2v
        6
    v2exe2v  
       Apr 6, 2022
    -- coding: gb-2312 --
    QingXuJiaZhi
        7
    QingXuJiaZhi  
       Apr 6, 2022
    1. 你的文件是自己新建的,还是网上下载的?
    2. 你使用什么编辑器?
    3. 你会查看文本文件的编码吗,你的这个文件是什么编码?
    deplivesb
        8
    deplivesb  
       Apr 6, 2022
    你这个不是 Python 新手,你是计算机新手
    imn1
        9
    imn1  
       Apr 6, 2022
    windows dos prompt 使用不是 utf 编码,它使用的字体也不支持跨字符集
    使用"chcp 65001"命令(不带引号),兼容 utf-8 输出,且更改字体为支持跨字符集的字体
    改字体这个需要一定的黑科技,请搜索相关文章(这个需要中文搜 google ,纯英文搜索没什么用)
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2732 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 34ms · UTC 08:18 · PVG 16:18 · LAX 01:18 · JFK 04:18
    ♥ Do have faith in what you're doing.