Changeset 191 for trunk/aeres/scripts
- Timestamp:
- 04/26/12 18:23:25 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/aeres/scripts/aeresrh.py
r183 r191 1 1 #!/usr/bin/env python 2 2 # -*- coding: iso-8859-1 -*- 3 4 __docformat__ = 'reStructuredText' 5 __autodoc__ = ['aeresrh'] 3 6 4 7 """ … … 53 56 aeresrh.py --ifile ${PROJECT}/data/aeresrh.xls 54 57 58 aeresrh.py --ifile ${HOME}/Downloads/personnel_franc\314\247oise.xls 59 55 60 TODO 56 61 ==== … … 76 81 77 82 $URL$ 83 84 - fplod 20120426 85 86 * big process in dictionnary using itertools 78 87 79 88 - fplod 20120410 … … 105 114 106 115 import datetime 116 117 import itertools 107 118 108 119 try: … … 140 151 """ 141 152 >>> people = {'pk1':{'firstname':'Brian', 'age':42}, 'pk2':{'firstname':'Alex', 'age':50}} 142 >>> find_in_dict(people, 'age', 42)153 >>> result = find_in_dict(people, 'age', 42) 143 154 144 155 http://stackoverflow.com/questions/8987631/searching-2-dimensional-dictionary … … 231 242 232 243 surname = sh.col_values(colsurname)[firstrow:lastrow] 233 print ('surname 0000 %s ' % surname)234 244 235 245 if is_verbose == True: … … 248 258 if is_verbose == True: 249 259 print(' temp arrival AAA%sAAA' % temp[rownum]) 250 #++ pb sh.datemodearrival = datetime.datetime(*xlrd.xldate_as_tuple(temp[rownum],sh.datemode))251 260 if temp[rownum] == '': 252 261 print('eee : pas de date arrivee colonne %d ' % rownum) 253 262 else: 254 print('iii : date arrivee pour %s ' % surname[rownum]) 255 #arrival.append(datetime.datetime(*xlrd.xldate_as_tuple(temp[rownum],datemode))) 263 arrival.append(datetime.datetime(*xlrd.xldate_as_tuple(temp[rownum],datemode))) 256 264 257 265 if is_verbose == True: … … 287 295 firstname_id = build_firstname_id(firstname) 288 296 # 289 author_id = [] 297 # populate dictionary 298 keys_for_all = [] 299 values_for_all = [] 300 keys_for_one = ['surname', 'firstname', 'arrival', 'publi'] 290 301 for index in range(len(surname_id)): 291 author_id.append('{surname_id}_{firstname_id}'.format(surname_id=surname_id[index], firstname_id=firstname_id[index])) 292 293 print('author id 0 %s ' % author_id[0]) 294 295 # populate dictionary 296 people = {} 297 keys = ('surname_id', 'firstname_id') 298 people = dict.fromkeys(author_id,keys) 299 people['COPPIN_elisabeth'] 300 for index, oneauthor_id in enumerate(author_id): 301 people[oneauthor_id] 302 #people[oneauthor_id]['surname_id'] = surname_id[index] 303 #people[oneauthor_id]['firstname_id'] = firsname_id[index] 304 # # people = {'pk1':{'firstname':'Brian', 'age':42}, 'pk2':{'firstname':'Alex', 'age':50}} 305 306 people['PINSARD_Francoise'] 307 find_in_dict(people, 'surname', 'PINSARD') 302 values_for_one=[] 303 values_for_one.append(surname[index]) 304 values_for_one.append(firstname[index]) 305 values_for_one.append(arrival[index]) 306 values_for_one.append(publi[index]) 307 values_for_all.append(dict(itertools.izip(keys_for_one,values_for_one))) 308 keys_for_all.append('{surname_id}_{firstname_id}'.format(surname_id=surname_id[index], firstname_id=firstname_id[index])) 309 310 311 if is_verbose == True: 312 print ('len keys_for_all : %d ' % len(keys_for_all)) 313 print ('person_id 0 : %s ' % keys_for_all[0]) 314 for index, key_for_all in enumerate(keys_for_all): 315 print ('person_id (key) : %s ' % key_for_all) 316 print ('associated info : %s ' % values_for_all[index]) 317 318 people = dict(itertools.izip(keys_for_all,values_for_all)) 319 320 if is_verbose == True: 321 print (' result looking for key PINSARD_francoise : %s ' % people['PINSARD_francoise']) 322 323 if is_verbose == True: 324 result = find_in_dict(people, 'surname', 'PINSARD') 325 print (' result looking for PINSARD %s ' % result) 308 326 309 327 # Run main, if called from the command line
Note: See TracChangeset
for help on using the changeset viewer.