class PasswordEntries(object):
def __init__(self, entries):
self.entries = entries
self._by_name = {entry.name: entry for entry in entries}
# Also add lookup by uid, gid, etc.
def __len__(self): return len(self.entries)
def __getitem__(self, i): return self.entries[i]
def get_name(self, name): return self._by_name.get(name)
# other public lookup methods here
entries = PasswordEntries(read_password_entries("/etc/passwd"))
print "root uses", entries.get_name("root").shell
print "_lp uses", entries.get_name("_lp").shell
It's a bad name for a reader, which is more closely tied with I/O. The suffix "-reader" suggests support for file operations (like 'close()'), use as a context manager, and awareness that the values will only be available once.The suffix "-s" does not. At the very least it suggests that it's possible to start a new iteration over the complete container of entries.
While you work to come up with a better name than "PasswdReader", what is your replacement name for "generator", as in:
>>> def f():
... yield 1
...
>>> x = f()
>>> x
<generator object f at 0x103ac3f50>
>>> x.__class__
<type 'generator'>
Your essay places the -or names into the -er category (they are, after all, indicators of action nouns), so why is "generator" a bad name?