I want a function to set the random seeds for several known packages.I'd like to create a library function which calls:
tf.set_random_seed(seed)
np.random.seed(seed)
random.seed(seed)
, but only if actually needed. In some cases the caller will be part of a program that uses numpy and in others it won't.
I want a single function, in its own importable file, which will set the random seed of various packages, but not to import the package unless used by the caller.
I can easily work-around this by inserting the method in each caller's file. But, I'm curious if there is a way to do what I want to do.
Can I somehow query the calling function and determine "In your scope, has numpy been imported"? If so, this function would call np.random.seed.