mailr17001 - /branches/interatomic/relax_errors.py


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by edward on June 20, 2012 - 13:35:
Author: bugman
Date: Wed Jun 20 13:35:46 2012
New Revision: 17001

URL: http://svn.gna.org/viewcvs/relax?rev=17001&view=rev
Log:
Created the list_to_text() RelaxError system function for prettifying the 
output of RelaxMultiSpinIDError.


Modified:
    branches/interatomic/relax_errors.py

Modified: branches/interatomic/relax_errors.py
URL: 
http://svn.gna.org/viewcvs/relax/branches/interatomic/relax_errors.py?rev=17001&r1=17000&r2=17001&view=diff
==============================================================================
--- branches/interatomic/relax_errors.py (original)
+++ branches/interatomic/relax_errors.py Wed Jun 20 13:35:46 2012
@@ -95,6 +95,35 @@
     file.close()
 
 
+def list_to_text(data):
+    """Convert the given Python list to a text representation.
+
+    @param data:    The list of Python objects.
+    @type data:     list
+    @return:        The English text version of the list.
+    @rtype:         str
+    """
+
+    # Initialise.
+    text = ''
+
+    # Loop over the elements, adding the to the list.
+    for i in range(len(data)):
+        # Add the text.
+        text += repr(data[i])
+
+        # Comma separators.
+        if i < len(data) - 2:
+            text += ', '
+
+        # Last separator.
+        if i == len(data) - 2:
+            text += ' and '
+
+    # Return the text.
+    return text
+
+
 # Base class for all errors.
 ############################
 
@@ -615,11 +644,11 @@
 class RelaxMultiSpinIDError(BaseError):
     def __init__(self, id, id_list=None):
         if id_list != None and id == '':
-            self.text = "The empty spin ID corresponds to multiple spins - 
%s." % id_list
+            self.text = "The empty spin ID corresponds to multiple spins, 
including %s." % list_to_text(id_list)
         elif id_list == None and id == '':
             self.text = "The empty spin ID corresponds to more than a single 
spin in the current data pipe."
         elif id_list != None:
-            self.text = "The spin ID '%s' corresponds to multiple spins - 
%s." % (id, id_list)
+            self.text = "The spin ID '%s' corresponds to multiple spins, 
including %s." % (id, list_to_text(id_list))
         else:
             self.text = "The spin ID '%s' corresponds to more than a single 
spin in the current data pipe." % id
 




Related Messages


Powered by MHonArc, Updated Wed Jun 20 14:20:02 2012