PEP 0263 Defining Python Source Code Encodings
PEP 0263
Defining Python Source Code Encodings
Python will default to ASCII as standard encoding if no other
encoding hints are given.
To define a source code encoding, a magic comment must
be placed into the source files either as first or second
line in the file, such as:
# coding=<encoding name>
or (using formats recognized by popular editors)
#!/usr/bin/python
# -*- coding: <encoding name> -*-
or
#!/usr/bin/python
# vim: set fileencoding=<encoding name> :
More precisely, the first or second line must match the regular
expression "coding[:=]\s*([-\w.]+)". The first group of this
expression is then interpreted as encoding name.
To aid with platforms such as Windows, which add Unicode BOM
marks to the beginning of Unicode files, the UTF-8 signature
'\xef\xbb\xbf' will be interpreted as 'utf-8' encoding as well
(even if no magic encoding comment is given).
但是在eclipse Pydev中指定源代码文件为utf-8格式,eclipse不会添加BOM(或其他原因),所以
要在第一行或者第二行添加匹配"coding[:=]\s*([-\w.]+)"的字符串
相关文档:
1.Python的扩展
Python扩展是指运用其他语言编写某些功能模块,供Python程序调用,常用的有Python的C扩展和C++扩展。Python扩展的目的主要有两个:一是为了功能需要,另外一个原因是为了性能需要。下面介绍一下在不运用工具的情况下,运用C和C++语言对Python进行扩展的步骤。
扩展的第一步是用C或C++创建一个源程序,然后 ......
shhgs 发布了关于《 Py 2.5 what's new 之 yield
》
之后,原来我不是特别关注 yield 的用法,因为对于2.3中加入的yield相对来说功能简单,它是作为一个 generator
不可缺少的一条语句,只要包含它的函数即是一个 generator 。但在2.3中,generator
不能重入,不能在运行过程中修改,不能引发异常,你要么是顺序 ......
原文:http://www.klipdas.com/blog/?p=python-decorator
python装饰器介绍
Python 2.2中引入的 classmethod() 和 staticmethod() 内置函数,你可以这样调用classmethod():
class A:
def foo(self, y):
print y
foo = classmethod(foo)
也可以这样:
class A:
@classmethod
def foo(sel ......
近来需要用Python对MySQL数据库进行操作。Python久闻其名,未见其“人”;数据库曾经很高分,早已还给先生,更无MySQL经验。于是一切从零开始,借机好好学习一番。
Python这个脚本语言确实名副其实,用了几天便喜欢上它啦。很简洁,很方便。以缩减作为模块分割符,读起来赏心悦目。python的内建数据类型( ......
知识点
1.线程是“轻量级”进程,因为相较于进程的创建和管理,操作系统通常会用较少的资源来创建和管理线程。操作系统要为新建的进程分配单独的内在空间和数据;相反,程序中的线程在相同的内存空间中执行,并共享许多相同的资源。多线程程序在结内存的使用效率要优于多进程程序。
2.python提供了完整的多线 ......