Changeset 1073 in lmdz_wrf for trunk


Ignore:
Timestamp:
Aug 31, 2016, 8:49:15 PM (9 years ago)
Author:
lfita
Message:

Adding `str_list_k': Function to obtain a list of types of values from a string giving a split character

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/generic_tools.py

    r1068 r1073  
    6363# Str_Bool: Function to transform from a String value to a boolean one
    6464# 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
    6566# stringList_dictKeysVals: Function to provide a dictionary with keys which contain values of lists from a string
    6667# subbasin_point: Function to provide sub-basins given a grid point following a matrix of trips
     
    37153716    elif typeval == 'complex':
    37163717        return complex(value)
    3717     elif typeval == 'str':
     3718    elif typeval == 'str' or typeval == 'S':
    37183719        return str(value)
    37193720    elif typeval == 'bool':
     
    79767977    return listv
    79777978
     7979def 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
     8008print str_list_k('1:@#:$:56', ':', 'S')
     8009print str_list_k('1:3.4:12.3', ':', 'np.float64')
     8010
     8011quit()
     8012
    79788013def stagger_unstagger(varv, dndims, udims):
    79798014    """ Function to de-stagger a variable
Note: See TracChangeset for help on using the changeset viewer.