jeudi 15 novembre 2018

Getting error while adding the float operation in join(random.choice(string.digits))

i have a program that is used to get the Large generation of data in that i have condition which will match the Integer and Character code is like that:

def getData(p_dataType, p_length, p_type):
    value =''
    dataType = p_dataType.upper()
    length=int(p_length)
    type=p_type.upper()
    if 'INT' in dataType or 'NUM' in dataType:
        if type == 'FIXED':
            return ''.join((random.choice(string.digits)) for _ in range(length))
        else:
            length=random.randint(1,length)
            return ''.join(random.choice(string.digits) for _ in range(length))

    elif 'CHAR' in dataType or 'STR' in dataType:
        if type == 'FIXED':
            return ''.join(random.choice(string.ascii_uppercase))+''.join(random.choice(string.ascii_lowercase) for _ in range(length-1))
        elif type != 'FIXED' and len(type)>0:
            return ''.join(random.choice(type.split(",")))
        else:
            length=random.randint(0,length)
            return ''.join(random.choice(string.ascii_uppercase))+''.join(random.choice(string.ascii_lowercase) for _ in range(length-1)) 

In This i want to add a condition for float and double

if 'FLOAT' in dataType or 'DOUBLE' in dataType:
        if type == 'FIXED':
            return ''.join(Float(random.choice(string.digits)) for _ in range(length))
        else:
            length=random.randint(1,length)
            return ''.join(random.choice(string.digits) for _ in range(length))

I'm not sure this way is good way and can we use string.digits for float Is it the right way to get that please help i will be greatfull with any help




Aucun commentaire:

Enregistrer un commentaire