Thursday, January 09, 2014

test string type (small update)

hi

this is a small update to the test string type function. which would propagate to the jc_makeDefWin(), in the same post.

i realised whilst running a few functions, that i had no case for boolean arguments. the reason for this was the possibility of using 1 and 0 as boolean arguments. but just to make things neater, here is a the same small function with boolean case:

def testStringType(string):
    def testType(var):
        def numTest(n):
            try:
                return float(n)
            except:
                return str(n)
        if var.isdigit():
            return int(var)
        elif  entry == 'True':
            return True
        elif entry == 'False':
            return False
        elif var.isalpha():
            return str(var)
        else:
            return numTest(var)
    cleanList=[]
    if ',' in var:
        clean = var.replace(' ', '')
        cleanList = clean.split(',')
        return cleanList
    else:
        single = testType(var)
        return single

simply reading if the string is either 'True' or 'False', before checking .isalpha().
you can fin the fully documented (and silly verbose) functions in the previous post.

regards