On 19 Apr, 2007, at 17:11, Will Henney wrote:

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?

That's strange, I'd expect UTF-8 to work just fine (and it does on my machine). What's the Character Set Encoding in Terminal's Window Preferences (on the Display page)?

Ronald

Cheers

Will



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

Attachment: smime.p7s
Description: S/MIME cryptographic signature

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

Reply via email to