Author: bugman Date: Wed May 28 15:32:39 2014 New Revision: 23515 URL: http://svn.gna.org/viewcvs/relax?rev=23515&view=rev Log: Created the is_list() and is_list_of_lists() functions for the lib.check_types module. Modified: trunk/lib/check_types.py Modified: trunk/lib/check_types.py URL: http://svn.gna.org/viewcvs/relax/trunk/lib/check_types.py?rev=23515&r1=23514&r2=23515&view=diff ============================================================================== --- trunk/lib/check_types.py (original) +++ trunk/lib/check_types.py Wed May 28 15:32:39 2014 @@ -1,6 +1,6 @@ ############################################################################### # # -# Copyright (C) 2012-2013 Edward d'Auvergne # +# Copyright (C) 2012-2014 Edward d'Auvergne # # # # This file is part of the program relax (http://www.nmr-relax.com). # # # @@ -148,6 +148,44 @@ return False +def is_list(val): + """Check if the given value is a Python list. + + @param val: The value to check. + @type val: anything. + @return: True if the value is a list, False otherwise. + @rtype: bool + """ + + # Not a list. + if not isinstance(val, list): + return False + + # Must be a list. + return True + + +def is_list_of_lists(val): + """Check if the given value is a Python list of lists. + + @param val: The value to check. + @type val: anything. + @return: True if the value is a list of lists, False otherwise. + @rtype: bool + """ + + # First dimension is not a list. + if not isinstance(val, list): + return False + + # Second dimension is not a list. + if not isinstance(val[0], list): + return False + + # Must be a list of lists. + return True + + def is_num(num): """Check if the given number is a Python or numpy int or float.