[Tutor] compiled images

John Fouhy john at fouhy.net
Thu Nov 17 22:27:06 CET 2005


On 18/11/05, Fred Lionetti <lordvader at gmail.com> wrote:
> Anyone have any idea as to how I could basically "compile" all my
> artwork into a data file for a python application?  Would this require
> compiling them into a *.dll/*.so?  It seems like there must be any
> easier way--Also, I need my application to work on windows + linux
> (and mac).

Maybe you could use shelve?

For instance, if you have myIcon1.gif, myIcon2.gif, myIcon3.gif:

####
import shelve
shelf = shelve.open('iconData')
for fn in ['myIcon1.gif', 'myIcon2.gif', 'myIcon3.gif']:
    shelf[fn] = file(fn, 'rb').read()
####

Then, in future, you should be able to access your icons by just:

 shelf = shelve.open('iconData')
 doSomething(shelf['myIcon2.gif'])

(and if your methods require a file-like object instead of just a
binary string, you can use the StringIO module)

There may be space or time issues --- you might want to experiment :-)
--- but it will definitely be cross-platform.

--
John.


More information about the Tutor mailing list