mailr17651 - in /trunk: check_types.py generic_fns/mol_res_spin.py


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

Header


Content

Posted by edward on October 02, 2012 - 10:52:
Author: bugman
Date: Tue Oct  2 10:52:35 2012
New Revision: 17651

URL: http://svn.gna.org/viewcvs/relax?rev=17651&view=rev
Log:
Created the check_types.is_unicode() function for Python 2+3 compatibility.

This is used in the generic_fns.mol_res_spin module.


Modified:
    trunk/check_types.py
    trunk/generic_fns/mol_res_spin.py

Modified: trunk/check_types.py
URL: 
http://svn.gna.org/viewcvs/relax/trunk/check_types.py?rev=17651&r1=17650&r2=17651&view=diff
==============================================================================
--- trunk/check_types.py (original)
+++ trunk/check_types.py Tue Oct  2 10:52:35 2012
@@ -47,3 +47,16 @@
     # Old style check.
     else:
         return isinstance(obj, file)
+
+
+def is_unicode(obj):
+    """Check if the given Python object is a unicode string.
+
+    @param obj:     The Python object.
+    @type obj:      anything
+    @return:        True if the object is a unicode string, False otherwise.
+    @rtype:         bool
+    """
+
+    # Check using the unicode type (set in the compat module for Python 3).
+    return isinstance(obj, unicode)

Modified: trunk/generic_fns/mol_res_spin.py
URL: 
http://svn.gna.org/viewcvs/relax/trunk/generic_fns/mol_res_spin.py?rev=17651&r1=17650&r2=17651&view=diff
==============================================================================
--- trunk/generic_fns/mol_res_spin.py (original)
+++ trunk/generic_fns/mol_res_spin.py Tue Oct  2 10:52:35 2012
@@ -42,6 +42,7 @@
 from warnings import warn
 
 # relax module imports.
+from check_types import is_unicode
 from data.mol_res_spin import MoleculeContainer, ResidueContainer, 
SpinContainer
 from generic_fns import exp_info, pipes, relax_re
 from relax_errors import RelaxError, RelaxNoSpinError, RelaxMultiMolIDError, 
RelaxMultiResIDError, RelaxMultiSpinIDError, RelaxResSelectDisallowError, 
RelaxSpinSelectDisallowError
@@ -80,7 +81,7 @@
         """
 
         # Handle Unicode.
-        if isinstance(select_string, unicode):
+        if is_unicode(select_string):
             select_string = str(select_string)
 
         self._union = None




Related Messages


Powered by MHonArc, Updated Tue Oct 02 11:00:01 2012