Python中的字符编码问题

风行水上 @ 2012-11-20 10:00:27
标签:

    Python程序的字符编码

    python默认源代码文件只包含ASCII字符。为了支持其他字符集,需要在源文件的第一行或第二行指定字符编码。

    #!/usr/bin/python
    # coding=utf8
    
    # -*- coding: utf8 -*-
    
    # vim: set fileencoding=utf8 :
    

    其中第二种是Emacs风格,第三种是Vim风格。

    详细地可以参考官方文档:Defining Python Source Code Encodings

    标签:

      分享到:
      comments powered by Disqus

      21/24ms