Fixing __str__ / __repr__ on Particle and Decay

Mon, 29 Apr 2013 15:26:46 +0200

author
Andy Buckley <andy@insectnation.org>
date
Mon, 29 Apr 2013 15:26:46 +0200
changeset 215
8a64587e884f
parent 214
fa07ed634b18
child 216
9d728fb2889d

Fixing __str__ / __repr__ on Particle and Decay

pyslha.py file | annotate | diff | comparison | revisions
     1.1 --- a/pyslha.py	Mon Apr 29 15:04:31 2013 +0200
     1.2 +++ b/pyslha.py	Mon Apr 29 15:26:46 2013 +0200
     1.3 @@ -39,6 +39,8 @@
     1.4     * Preserve comments from read -> write (needs full-line/inline comment
     1.5       separation?). Can use separate comment dicts in Block and Decay, and
     1.6       attach a multiline .comment attr to the returned/written dicts.
     1.7 +   * Only allow integers to be used as block entry indices, to allow multiple
     1.8 +     values (request, if possible, from Anders & Are).
     1.9  
    1.10    Later/maybe:
    1.11     * Identify HERWIG decay matrix element to use in ISAWIG
    1.12 @@ -46,7 +48,7 @@
    1.13  """
    1.14  
    1.15  __author__ = "Andy Buckley <andy.buckley@cern.ch"
    1.16 -__version__ = "2.0.0a0"
    1.17 +__version__ = "2.0.0"
    1.18  
    1.19  
    1.20  def _mkdict():
    1.21 @@ -254,12 +256,9 @@
    1.22      def __cmp__(self, other):
    1.23          return cmp(other.br, self.br)
    1.24  
    1.25 -    def __str__(self):
    1.26 +    def __repr__(self):
    1.27          return "%.8e %s" % (self.br, self.ids)
    1.28  
    1.29 -    def __repr__(self):
    1.30 -        return self.__str__()
    1.31 -
    1.32  
    1.33  class Particle(object):
    1.34      """
    1.35 @@ -288,7 +287,7 @@
    1.36              return cmp(self.pid, other.pid)
    1.37          return cmp(abs(self.pid), abs(other.pid))
    1.38  
    1.39 -    def __str__(self):
    1.40 +    def __repr__(self):
    1.41          s = str(self.pid)
    1.42          if self.mass is not None:
    1.43              s += " : mass = %.8e GeV" % self.mass
    1.44 @@ -299,12 +298,6 @@
    1.45                  s += "\n  %s" % d
    1.46          return s
    1.47  
    1.48 -    def __repr__(self):
    1.49 -        return self.__str__()
    1.50 -
    1.51 -
    1.52 -
    1.53 -
    1.54  
    1.55  def readSLHA(spcstr, ignorenobr=False):
    1.56      """
    1.57 @@ -380,7 +373,6 @@
    1.58  
    1.59  def writeSLHABlocks(blocks, precision=8):
    1.60      """Return an SLHA definition as a string, from the supplied blocks dict."""
    1.61 -    # TODO: Pay attention to space-padding and minus signs for column alignment
    1.62      sep = 3 * " "
    1.63      blockstrs = []
    1.64      for bname, b in blocks.iteritems():

mercurial