6.2.4.2.19. attrlist

Comienzo python section to interscript/core/mxTools.py[20 /26 ] Siguiente Previo Primero Último
   141: #line 1663 "mxTools.pak"
   142: def attrlist(object_list,attrname):
   143:   alist = []
   144:   for object in object_list:
   145:     if hasattr(object, attrname):
   146:       alist.append(getattr(object, attrname))
   147:   return alist
   148: 
End python section to interscript/core/mxTools.py[20]
Comienzo C section to interscript/core/mxTools.c[21 /30 ] Siguiente Previo Primero Último
  1428: #line 1671 "mxTools.pak"
  1429: 
  1430: Py_C_Function( mxTools_attrlist,
  1431:                "attrlist(objectlist,attrname)\n\n"
  1432:                "Returns a list of all attributes with the given name\n"
  1433:                "found among the objects in objectlist."
  1434:                )
  1435: {
  1436:     PyObject *list,*l=0;
  1437:     PyObject *name;
  1438:     register int i;
  1439:     int length;
  1440: 
  1441:     Py_Get2Args("OO",list,name);
  1442: 
  1443:     length = PySequence_Length(list);
  1444:     if (length < 0)
  1445:         Py_Error(PyExc_TypeError,
  1446:                  "first argument must be a sequence");
  1447: 
  1448:     Py_Assert(PyString_Check(name),
  1449:               PyExc_TypeError,
  1450:               "second argument must be a string");
  1451: 
  1452:     l = PyList_New(0);
  1453:     if (!l)
  1454:         goto onError;
  1455: 
  1456:     for(i = 0; i < length; i++) {
  1457:         PyObject *v;
  1458:         PyObject *w;
  1459: 
  1460:         v = PySequence_GetItem(list,i);
  1461:         if (!v)
  1462:             goto onError;
  1463: 
  1464:         w = PyObject_GetAttr(v,name);
  1465:         if (w) {
  1466:             PyList_Append(l,w);
  1467:             Py_DECREF(w);
  1468:         }
  1469:         else if (!PyErr_ExceptionMatches(PyExc_AttributeError))
  1470:             goto onError;
  1471:         else
  1472:             PyErr_Clear();
  1473:     }
  1474:     return l;
  1475: 
  1476:  onError:
  1477:     Py_XDECREF(l);
  1478:     return NULL;
  1479: }
  1480: 
End C section to interscript/core/mxTools.c[21]