mardi 22 mars 2022

Overwrite a global variable outside of the script

When I am calling the function func in a Jupyter notebook or another script, how can I overwrite the global variable alpha below outside of the script? (I don't want to pass the alpha as the function argument)

# script.py
alpha = 10

def func(a, b):
    return a * alpha + b

For example, the user defines his own alpha in a csv file and have the following code in Jupyter notebook or another script. Is it possible to overwrite on the one defined in script.py?

# Jupyter notebook
from script import func

parameters = pd.read_csv('parameters')
alpha = parameters[0]

print(func(10, 20))

Thank you in advance!

Aucun commentaire:

Enregistrer un commentaire