samedi 28 août 2021

designing python code, use var from one method within another

I am having a code where I run several checks, like

def run_checks():
  check_on_color()
  check_on_size()

normally all the checks are independent, but in a very few cases, it would be good to use a value within one of these checks and use it within another. What would be the best pythonic way to do this? Is it ok to define a global var then, or should I rather return the value like:

def run_checks():
  one_var = check_on_color()
  check_on_size(one_var)

I don't like returning var so much, because its not the actual task of the method to return something, its more a byproduct. But using a global var to transfer a value from one independent method to another also seems quite quirky.

Aucun commentaire:

Enregistrer un commentaire