On Mother's Shoulder

Our new born son Tomas on his mother’s shoulder. If you want to see Tomas, or watch more pictures: come visit us!

Find out if every element of a list is part of another, with Python

I wanted to check if every element of one list or tuple is part of another one using Python. A set has the issubset()-method, but I couldn’t find anything build-in for a tuple. It was, however, rather quickly done: >>> r = (1,2) >>> l = (3,4,1,5,2) >>> False not in [ e in l for e in r ] True >>> r = (1,9) >>> False not in [ e in l for e in r ] False Why I’m posting this?

Using Globals in Pylons.. everywhere

In Pylons v1.0 you can define global variables by adding them to the Globals-class. If you want a variable called spam and you want it to be globally available, your `lib.app_globals. Globals`-class would look like this: class Globals(object): def __init__(self, config): self.cache = CacheManager(**parse_cache_config_options(config)) self.spam = False To use it in a model-module for example, you have to import app_globals from the pylons module, like this: from pylons import app_globals as g print g.

AppleScript exporting photos from Aperture

The following AppleScript will: Prompt for a destination folder Ask for an album name, which will be a folder in destination folder Get currently selected photo(s) from Aperture Store the image files using the Image ID of Aperture Store some META information in a text file, with similar name as image file The export format is PNG 1024x1024. I needed only that, so I hardcoded it. Note dependencies: You need the renameFile, joinList and splitString functions found in earlier blog entries.

Splitting as string and joining a list using AppleScript

Two small helper AppleScript functions for joining a list and splitting a string given delimiter. Sure, quite an easy task, but it involves setting a global delimiter. Bit like FS in shell. I hope this helps a few folks out there starting out with AppleScript. to joinList(aList, delimiter) set retVal to "" set prevDelimiter to AppleScript's text item delimiters set AppleScript's text item delimiters to delimiter set retVal to aList as string set AppleScript's text item delimiters to prevDelimiter return retVal end joinList to splitString(aString, delimiter) set retVal to {} set prevDelimiter to AppleScript's text item delimiters log delimiter set AppleScript's text item delimiters to {delimiter} set retVal to every text item of aString set AppleScript's text item delimiters to prevDelimiter return retVal end splitString Here a few lines showing how to use them: