Dethe Elza <delza <at> livingcode.org> writes:
>      library = plistlib.readPlist(os.path.expanduser('~/Pictures/ 
> iPhoto Library/AlbumData.xml'))
>      for photo in library['Master Image List'].values():
>          if hasattr(photo, 'Rating') and photo.Rating > 0:
>              print '%s: %d stars' % (photo.Caption, photo.Rating)
> 
> How's that?
> 

Hi Dethe,

Thanks for the example scripts! They work great if the comments only contain
ascii characters, but I found I had to make a small modification to make it work
with the captions in my database:

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
import plistlib, os
outputcodec = "latin-1"         # or "utf-8", or "ascii", or ....
library = plistlib.readPlist(
    os.path.expanduser('~/Pictures/iPhoto Library/AlbumData.xml'))
for photo in library['Master Image List'].values():
    if hasattr(photo, 'Rating') and photo.Rating > 0:
        try:
            thiscaption = photo.Caption.encode(outputcodec)
        except UnicodeEncodeError: 
            thiscaption = "Cannot encode caption in codec %s" % outputcodec
        print '%s: %d stars' % (thiscaption, photo.Rating)
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

My initial try was to use "utf-8" as the output codec, but that wrote garbage
characters when I ran it in Terminal.app - any idea why?

Cheers

Will



_______________________________________________
Pythonmac-SIG maillist  -  Pythonmac-SIG@python.org
http://mail.python.org/mailman/listinfo/pythonmac-sig

Reply via email to