#!/usr/bin/env python # -*- coding: utf-8 -*- ''' @Author: [email protected] @Version: @Date: @Note: ''' import os, base64 icon = open('ya.png','rb') iconData = icon.read() iconData = base64.b64encode(iconData) LIMIT = 60 liIcon = [] while True: sLimit = iconData[:LIMIT] iconData = iconData[LIMIT:] liIcon.append('\'%s\'' %sLimit) if len(sLimit) < LIMIT: break print os.linesep.join(liIcon)ya.png:
得到的Base64代码为:
'iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAAGXRFWHRTb2Z0'
'd2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAdhJREFUeNrsVV1OwkAQnlYK'
'RH4sVfFBTYr6rpzAegO8AZwAegLhBMUTqCcAb8AN4AAmkKgvIqUiIAYIztSF'
'NBvaygMvhkkm293uzDc/37TCbDaDdYoIa5YNgK8IcJrP4nqDqjrOa6gPqPeO'
'MwO1wJ4t9k6fPZV9AWiVUevqSUptv7Vh0O9fMRBe6uxumoGAH4DoiEjvvHcg'
'oSjAMuJFi0QjF7jm5s5X7UH1s9erjr6GoOwqmqMcixIN+oOqS2a+JZoLpd88'
'Oj6UX55fLVaKFsuIAFNc9HSedfSvxfpSdWMRGV+bZheSB/sEdseMyXmJd55Q'
'5CKuDdQEahH3qiRJFeGsoHrRtDYcDMvTyRSSyT2NNZac8N3URME2b2DEFmqp'
'a1ogSQFwMtJtDkqdjtmKxSIQDocoE33JHR3vUAa3FDGqIcvxPw+azXPL+oDR'
'6BtYBrzQ2SNqBaNusv4RcVeYZO8vbTYUCtpzMR5P0liinGX1eP9+nwpPAEMK'
'bNnlROcNNxvROwFPADkYtBt6bvP9rJCJRsIgioL9DvdZLwCqp0bRkBFKZhnb'
'qIQ78e0iOqNSGUFkEO7JprIA5gYNfh3DpRu7uCAMRskWY1qe2deItjbA5pf5'
'/wF+BBgAfqCdwaJDsXYAAAAASUVORK5CYII='