标签:path tran pre esc cap print test 去掉 python笔记
1.使用python去掉unicode前面的u。如 u‘../123/haha/test.png‘ 变成../123/haha/test.png,代码如下:(python2.7)
path=u‘../../../test.png‘.encode(‘raw_unicode_escape‘) print path
运行结果:
>>>../../../test.png
2.使用python将图片变成数组后base64加密,代码如下:
def transformImage(imagepath):
path=imagepath.encode(‘raw_unicode_escape‘)
f = open(path,‘rb‘).read()
res = bytearray(f)
bs64 = base64.b64encode(res)
# print bs64
return bs64
print transformImage(u‘../123/haha/test.png‘)
标签:path tran pre esc cap print test 去掉 python笔记
原文地址:http://www.cnblogs.com/panpan0301/p/7845697.html