- Timestamp:
- Aug 31, 2016, 8:49:15 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/generic_tools.py
r1068 r1073 63 63 # Str_Bool: Function to transform from a String value to a boolean one 64 64 # str_list: Function to obtain a list from a string givin a split character 65 # str_list_k: Function to obtain a list of types of values from a string giving a split character 65 66 # stringList_dictKeysVals: Function to provide a dictionary with keys which contain values of lists from a string 66 67 # subbasin_point: Function to provide sub-basins given a grid point following a matrix of trips … … 3715 3716 elif typeval == 'complex': 3716 3717 return complex(value) 3717 elif typeval == 'str' :3718 elif typeval == 'str' or typeval == 'S': 3718 3719 return str(value) 3719 3720 elif typeval == 'bool': … … 7976 7977 return listv 7977 7978 7979 def str_list_k(string, cdiv, kind): 7980 """ Function to obtain a list of types of values from a string giving a split character 7981 string= String from which to obtain a list ('None' for None) 7982 cdiv= character to use to split the string 7983 kind= kind of desired value (as string like: 'np.float', 'int', 'np.float64', ....) 7984 >>> str_list_k('1:@#:$:56', ':', 'S') 7985 ['1', '@#', '$', '56'] 7986 >>> str_list_k('1:3.4:12.3', ':', 'np.float64') 7987 [1.0, 3.3999999999999999, 12.300000000000001] 7988 """ 7989 fname = 'str_list' 7990 7991 if string.find(cdiv) != -1: 7992 listv = string.split(cdiv) 7993 else: 7994 if string == 'None': 7995 listv = None 7996 else: 7997 listv = [string] 7998 7999 if listv is not None: 8000 finalist = [] 8001 for lv in listv: 8002 finalist.append(typemod(lv, kind)) 8003 else: 8004 finallist = None 8005 8006 return finalist 8007 8008 print str_list_k('1:@#:$:56', ':', 'S') 8009 print str_list_k('1:3.4:12.3', ':', 'np.float64') 8010 8011 quit() 8012 7978 8013 def stagger_unstagger(varv, dndims, udims): 7979 8014 """ Function to de-stagger a variable
Note: See TracChangeset
for help on using the changeset viewer.