comparison lookup_list.py @ 167:4803cb76e26b

Updated documentation
author Joseph Turian <turian@gmail.com>
date Mon, 12 May 2008 18:51:42 -0400
parents ad144fa72bf5
children cb6b945acf5a
comparison
equal deleted inserted replaced
166:ee11ed427ba8 167:4803cb76e26b
4 class LookupList(object): 4 class LookupList(object):
5 """ 5 """
6 A LookupList is a sequence whose elements can be named (and unlike 6 A LookupList is a sequence whose elements can be named (and unlike
7 a dictionary the order of the elements depends not on their key but 7 a dictionary the order of the elements depends not on their key but
8 on the order given by the user through construction) so that 8 on the order given by the user through construction) so that
9 following syntactic constructions work as one would expect: 9 following syntactic constructions work as one would expect::
10 example = LookupList(['x','y','z'],[1,2,3]) 10 example = LookupList(['x','y','z'],[1,2,3])
11 example['x'] = [1, 2, 3] # set or change a field 11 example['x'] = [1, 2, 3] # set or change a field
12 print example('z','y') # prints [3,2] 12 print example('z','y') # prints [3,2]
13 x, y, z = example 13 x, y, z = example
14 x = example[0] 14 x = example[0]
19 example.append_keyval('u',0) # adds item with name 'u' and value 0 19 example.append_keyval('u',0) # adds item with name 'u' and value 0
20 print len(example) # number of items = 4 here 20 print len(example) # number of items = 4 here
21 example2 = LookupList(['v', 'w'], ['a','b']) 21 example2 = LookupList(['v', 'w'], ['a','b'])
22 print example+example2 # addition is like for lists, a concatenation of the items. 22 print example+example2 # addition is like for lists, a concatenation of the items.
23 example + example # throw an error as we can't have duplicate name. 23 example + example # throw an error as we can't have duplicate name.
24 Note that the element names should be unique. 24 @note: The element names should be unique.
25 @todo: Convert this documentation into doctest
26 format, and actually perform doctest'ing:
27 U{http://epydoc.sourceforge.net/manual-epytext.html#doctest-blocks}
25 """ 28 """
26 def __init__(self,names=[],values=[]): 29 def __init__(self,names=[],values=[]):
27 assert len(values)==len(names) 30 assert len(values)==len(names)
28 self.__dict__['_values']=values 31 self.__dict__['_values']=values
29 self.__dict__['_name2index']={} 32 self.__dict__['_name2index']={}