您的位置:首页 > 编程语言 > Python开发

python 添加中文注释

2011-10-13 11:01 435 查看
在文件头上写入:

#coding=gbk

例如:

#coding=gbk
#mine,二进制相互转换
try:
from binascii import a2b_qp, b2a_qp
except ImportError:
print u'没有找到 binascii 函数库'

#二进制 ----> 可打印字符
file = open( 'd:\\tmp\\ua.ppt', 'rb' ) #读取二进制文件
data = file.read()
odata = b2a_qp( data, 0, 0 )

ofile = open( 'd:\\tmp\\o_ua.txt', 'w' ) #以文本文件方式写入
ofile.write( odata )

ofile.close()
file.close()

#可打印字符 ---> 二进制
file = open( 'd:\\tmp\\o_ua.txt', 'r' ) #读取文本文件
data = file.read()
odata = a2b_qp( data, 0 )

ofile = open( 'd:\\tmp\\o_ua.ppt', 'wb' ) #以二进制方式写入
ofile.write( odata )

ofile.close()
file.close()
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: