Question
For a possibly convoluted reason (see below), I want to do something like the following:
def import_np():
import numpy
return numpy.array([0])
def test_np():
return numpy.array([1])
Now if I try calling these two methods, the first works but the second doesn't: it says numpy is not defined
. How can I fix this?
Background
I would like to import an in-house module of which we have many versions (edit: to clarify, we branch for every release). Ideally, I'd like to parametrise the import statement, but I can't do that, so I thought I could have a function that looks like this:
def import_version(path_to_version):
sys.path.append(path_to_version)
import the_module
However, I can't use the_module
outside of this method, which has led to my question above.