tags:

views:

53

answers:

2

i am trying to convert bitmap images into a base64 string before inserting it into database as binary blobs. The base64 string needs to be encoded in such a way that their is a new line character after every 76 characters. what is the best pythonic way of doing this ?

+2  A: 
'\n'.join(s[pos:pos+76] for pos in xrange(0, len(s), 76))
nosklo
A: 

Since Base64 mandates a fixed line length (64 or 76 characters, depending on which version you look at), the library that produces the Base64 String should already do that (or at least have an option to do that).

Joachim Sauer