python 添加中文注释

在文件头上写入:

#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()

 

posted @ 2011-10-13 11:01  keepfocus  阅读(2055)  评论(0编辑  收藏  举报