Skip to content

Instantly share code, notes, and snippets.

@brettkelly
Created May 17, 2011 22:54
Show Gist options
  • Save brettkelly/977600 to your computer and use it in GitHub Desktop.
Save brettkelly/977600 to your computer and use it in GitHub Desktop.
foo.py
class ArticleFolderCollection(object):
"""A simple iterable collection for ArticleFolder objects"""
def __init__(self):
self.folders = []
def __iter__(self):
for f in self.folders:
yield f
def __contains__(self, folder):
for f in self.folders:
if f.id == folder.id:
return True
return False
def __repr__(self):
out = '%d %s' % (len(self.folders),' folders\n')
for f in self.folders:
out += '%s : %s\n' % (f.id, f.name)
return out
def __len__(self):
return len(self.folders)
def append(self,folder):
self.folders.append(folder)
def findFolderByField(self, field, value):
for f in self.folders:
if f[field] == value:
return f
return None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment