base64模块是用来作base64编码解码的。这种编码方式在电子邮件中是很常见的。它可以把不能作为文本显示的二进制数据编码为可显示的文本信息。编码后的文本大小会增大1/3。这里主要介绍一下base64的8个方法(encode, decode, encodestring, decodestring, b64encode,b64decode, urlsafe_b64decode,urlsafe_b64encode):

    1、encode,decode:用来编码和 解码文件的,也可以对StringIO里的数据做编解码
    2、encodestring,decodestring:用来编码和解码字符串
    3、b64encode和b64decode:用来编码和解码字符串,并且有一个替换符号字符的功能

小实例:

python解码base64学习笔记_python解码base64

#@小五义 http://www.cnblogs.com/xiaowuyi#将c盘下1.txt(base64编码的内容)解码后存在c盘下2.txt中import base64
 
filea = open(r'c:\1.txt','r')   
lines = filea.readlines()
writefile=open(r'c:\2.txt','w')for i in lines:   
        word = i.strip()
        b = base64.decodestring(word)        print b
        writefile.write(b)
        writefile.write('\n')
writefile.close()
filea.close()

python解码base64学习笔记_python解码base64

转载请注明:@小五义 http://www.cnblogs.com/xiaowuyi