vendredi 30 juin 2017

how to read values from a text file, store it in array and loop through it in PYTHON

Based on package dimension: Height , Length, Width and Weight, I'm creating 3 package categories: Letter, Parcel-Small and Parcel-Large. Here is the code in python:

def category(row):
    if row['Height'] <=0.98 and row['Length'] <= 9.84 and row['Width'] 
    <= 13.89 and row['WEIGHT'] <= 1.65:
        val = 'Letter'
    elif row['Height'] <=6.29 and row['Length'] <= 13.77 and 
    row['Width'] <= 17.71 and row['WEIGHT'] <= 4.4:
        val = 'Parcel-Small'        
    elif row['Height'] <=6.29 and row['Length'] <= 13.77 and 
    row['Width'] <= 17.71 and row['WEIGHT'] <= 4.4:
        val = 'Parcel-Large'
return val

As seen these dimension values are hardcoded. I want to take the inputs(package category name, height, length, width, weight) from a text file which in the format like :

[Package Category : Height, Length, Width, Weight]

It should read as many categories as specified by user and the code should be something like this :

for each package category:
    if row['Height'] <= Height and row['Length'] <=Length and row['Width'] 
    <= Width and row['WEIGHT'] <= Weight:
        val = 'Package Category'

Can someone give a actual code for the pseudo code given above? Thanks

Aucun commentaire:

Enregistrer un commentaire