mercredi 23 mars 2022

Program design - update global variable value

Suppose I have a global variable pi=3.14 in a script. In most cases, the pi is used as 3.14 in functions and classes in the script. However, the user might need to change the value sometimes. Can the user change the value of pi in the script without modifying the script? (The user don't want to pass the pi to the function as argument.)

For example, the user defines his own pi in another script or Jupyter notebook, and import the relevant functions and classes. Then, the functions and classes will use the new pi. From a software design perspective, is there a good way to do that?

Thank you in advance!

Aucun commentaire:

Enregistrer un commentaire