import base64 f = open("m1.jpg", "rb") res = f.read() s = base64.b64encode(res) f = open("hello.txt","w") f.write(s)