I have been writing some python scripts to automate some tasks at work for quite some time now. Each time, the script follows the same pattern, of main calling different functions(which in turn call other) and controlling the overall flow:
def func2(aws_client, xyz_client, var1, var2, dict1, dict2):
...
def func1(aws_client, xyz_client, var1, var2, dict1):
...
func2(aws_client, xyz_client, var1, var2, dict1, dict2)
def main():
func1(aws_client, xyz_client, var1, var2, dict1)
While this works fine, I end up seeing myself passing multiple same parameters in particular order between functions and find it hard to maintain and keep track.
I read in a few places that taking a class based approach might help. ie, all the shared state are just members of the class and to access/set them by self.aws_client etc.
However, since I am mainly automating stuff, its hard to think of this as a Class(something as a real world object/an entity). So in this case, are we using classes just as a workaround for shares data? Are there some best practices to follow for such scripts?
Aucun commentaire:
Enregistrer un commentaire