Ok, a real unload is not existing in Python. (as Vladimir already mentioned)
Assume you have a file foo.py with the following content:
NAME = "MyName"
def foo_funct():
print "foo.foo_funct called", NAME
Importing and reloding works fine:
>>> import foo
>>> foo.foo_funct()
foo.foo_funct called MyName
>>> foo.NAME = "ANewName"
>>> foo.foo_funct()
foo.foo_funct called ANewName
>>> reload( foo )
<module 'foo' from 'foo.pyc'>
>>> foo.foo_funct()
foo.foo_funct called MyName
If I understood you right, this is what you want:
try:
reload(foo)
except NameError:
import foo
reload will fail with a NameError if foo is not already imported. So catch this one and execute a normal import then.