store .png file in a script
Ian Kelly
ian.g.kelly at gmail.com
Sun Jun 6 11:01:22 EDT 2010
On Sun, Jun 6, 2010 at 8:28 AM, Navid Parvini <parvini_navid at yahoo.com> wrote:
>
> Dear All,
>
> Would you please let me know that how can I store a .png or .gif or .jpg file, in a python script?
>
> Thank you in advance.
>
> Navid
Encode it in base64 and store it in a triple-quoted string literal:
import base64
png_data = """
iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd1PeAAAAAXNSR0IArs4c
6QAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9oGBg40CoQ7CHYAAAAZ
dEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIEdJTVBXgQ4XAAAADElEQVQI12P4
//8/AAX+Av7czFnnAAAAAElFTkSuQmCC
"""
png = base64.b64decode(png_data)
Cheers,
Ian
More information about the Python-list
mailing list