vendredi 18 janvier 2019

Better Python Design Pattern when calling same function multiple times

I have the below Python code to store key and value attributes to Key Value database.

 try:
        persistence.set(student_first_name + ".firstname", student_first_name)
        persistence.set(student_last_name + ".last", student_last_name)
        persistence.set(student_id + ".id", student_id)
        persistence.set(student_sex + ".sex", student_sex)
        persistence.set(student_year + ".year", student_year)

    except ValueError:
        exception

Is there a better Design Pattern that calling the same persistence.set() with different parameters again and again? I have the same code being called in for loop in a different part of the application too.

Aucun commentaire:

Enregistrer un commentaire