python获得图片base64编码示例

代码如下:

#!/usr/bin/env python# -*- coding: utf-8 -*-

import os, base64

icon = open(‘ya.png’,’rb’)icondata = icon.read()icondata = base64.b64encode(icondata)limit = 60liicon = []while true: slimit = icondata[:limit] icondata = icondata[limit:] liicon.append(‘\’%s\” %slimit) if len(slimit) < limit: breakprint os.linesep.join(liicon)