Template:Python

From VLECK
Jump to: navigation, search
 
{{{code}}}



example
def getAttributesOfObject(o, exclusion_prefix="_"):
  """
  return all "normal" attributes of an object
  @param o: object
  @param exclusion_prefix: leading characters of excluded attribute names (default underscore)
  @return: dictionary
  """
  result = {}
  for name in dir(o):
    value = getattr(o, name)    
    if not (inspect.isclass(value) 
         or inspect.ismethod(value) 
         or inspect.isfunction(value) 
         or inspect.isbuiltin(value)
         or name.startswith(exclusion_prefix)
         or str(type(value)) == "<type 'method-wrapper'>"):
      result[name] = value
  return result