Created
May 17, 2011 22:54
-
-
Save brettkelly/977600 to your computer and use it in GitHub Desktop.
foo.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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