Package SimPy :: Module Lister

[hide private]
[frames] | no frames]

# Source Code for Module SimPy.Lister

     1  #!/usr / bin / env python
     2  # $Revision: 163 $ $Date: 2008-12-15 12:47:44 +0100 (Mo, 15 Dez 2008) $ kgm
     3  """Lister 2.0
     4  Pretty-printer for SimPy class objects
     5  """
     6  __version__ = '2.0 $Revision: 163 $ $Date: 2008-12-15 12:47:44 +0100 (Mo, 15 Dez 2008) $'
     7
     8 -class Lister(object):
     9      indent = 0
    10 -    def __str__(self):
    11          Lister.indent += 1
    12          result = (' < Instance of %s, id %s:\n%s' % (self.__class__.__name__,
    13                                                 id(self),self.attrnames())) + '\t' * (Lister.indent - 1) + ' > '
    14          Lister.indent -= 1
    15          return result
    16
    17 -    def attrnames(self):
    18          result = ''
    19          for attr in self.__dict__.keys():
    20              if attr[:2] == '__': #builtin
    21                  pass
    22              elif attr[0] == '_': #private
    23                  pass
    24              else:
    25                  result = result + '\t' * Lister.indent + '.%s=%s\n' % (attr, self.__dict__[attr])
    26          return result
    27 -    def __repr__(self):
    28          Lister.indent += 1
    29          result = (' < Instance of %s, id %s:\n%s' % (self.__class__.__name__,
    30                                                 id(self),self.attrnames())) + '\t' * (Lister.indent - 1) + ' > '
    31          Lister.indent -= 1
    32          return result
    33