What does %%(%s)s mean/expand to in Python? What does rowshtml += (rowhtml % ((fieldname, ) * 3)) expand to? Kindly explain.

satishmlmlml at gmail.com satishmlmlml at gmail.com
Wed Oct 29 02:15:41 EDT 2014


def fetchRecord(db, form): 
 try: 
  key = form['key'].value 
  record = db[key] 
  fields = record.__dict__ 
  fields['key'] = key 
 except: 
  fields = dict.fromkeys(fieldnames, '?') 
  fields['key'] = 'Missing or invalid key!' 
 return fields 
def updateRecord(db, form): 
 if not 'key' in form: 
  fields = dict.fromkeys(fieldnames, '?') 
  fields['key'] = 'Missing key input!' 
 else: 
  key = form['key'].value 
  if key in db: 
   record = db[key] 
 else: 
   from person import Person 
   record = Person(name='?', age='?') 
 for field in fieldnames: 
   setattr(record, field, eval(form[field].value)) 
  db[key] = record 
  fields = record.__dict__ 
  fields['key'] = key 
 return fields 
db  =  shelve.open(shelvename) 
action = form['action'].value if 'action' in form else None 
if action == 'Fetch': 
 fields = fetchRecord(db, form) 
elif action == 'Update': 
 fields = updateRecord(db, form) 
else: 
 fields = dict.fromkeys(fieldnames, '?') 
 fields['key'] = 'Missing or invalid action!' 
db.close() 
print(replyhtml % htmlize(fields)) 

What does %%(%s)s mean in Python? 

also 
what does 
rowshtml += (rowhtml % ((fieldname,) * 3)) expand to? 



More information about the Python-list mailing list