首页 > 编程语言 > 详细

python笔记

时间:2017-11-16 19:22:28      阅读:243      评论:0      收藏:0      [点我收藏+]

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‘)

  

python笔记

原文:http://www.cnblogs.com/panpan0301/p/7845697.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!