def fields2csv_head(fields, prefix=''):
 line = []
 for (field, subfields) in fields.iteritems():
  if ((subfields is True) or callable(subfields)):
   line.append((prefix + field))
  elif isinstance(subfields, dict):
   line += fields2csv_head(subfields, prefix=((prefix + field) + '.'))
 return line

def fields2csv_head ( fields , prefix = '' ) : line = [ ] for ( field , subfields ) in fields . iteritems ( ) : if ( ( subfields is True ) or callable ( subfields ) ) : line . append ( ( prefix + field ) ) elif isinstance ( subfields , dict ) : line += fields2csv_head ( subfields , prefix = ( ( prefix + field ) + '.' ) ) return line
given an dictionnary fields .