macPython: accessing string data in resource files

Jacob Kaplan-Moss jacobkm at
Tue May 29 12:38:59 EDT 2001

Jesse --

Well, the module you want is the Res module.  There's no documentation 
for this module that I'm aware of, but the docstrings are pretty good.

To get at a STR# resource, try something like this:

Python 2.1 (#92, Apr 24 2001, 23:59:23)  [CW PPC GUSI2 THREADS] on mac
Type "copyright", "credits" or "license" for more information.
>>> import Res
>>> resfile = "strings.rsrc"  # or the full path to your res file
>>> rf = Res.FSpOpenResFile(resfile, 0)
>>> strh = Res.GetResource("STR#", 128)
'\x00\x04\x18this is the first string\tstring #2\x12and a third 
string\x1afinally, the fourth string'

Now, at this point you've got the STR# data, but it is encoded as a 
series of Pascal strings.  The resource data starts with a null byte, 
the next byte is the number of strings, and then each string begins with 
a byte telling how long the following string is.  You could probably 
write a function which converts this into a list, but as far as I'm 
aware of there is no library function which will do it for you.

Hope that helps,


More information about the Python-list mailing list