P
pranav.choudhary
Hi
I am new to python. I wanted to know if there is an opposite of "import"
I am new to python. I wanted to know if there is an opposite of "import"
I am new to python. I wanted to know if there is an opposite of "import"
If you mean 'import' adds something, so you ask how to get rid ofHi
I am new to python. I wanted to know if there is an opposite of "import"
Hi
I am new to python. I wanted to know if there is an opposite of "import"
If you want to remove the module from a namespace into which you
imported it, you can do that with del:
import amodule
amodule.afunction() # Works fine
del amodule
amodule.afunction() # Will die now
Note that this doesn't get rid of a module entirely. Python will still
holds on to the module, and if you just import it again at this point,
it won't be re-executed - you'll just get another reference to the
original module.
Is that guaranteed, or is that just until the garbage collector has removed
the module (at some arbitrary point)?
It is guaranteed that simply deleting the module from the module whichGerhard said:Is that guaranteed, or is that just until the garbage collector has
removed the module (at some arbitrary point)?
Simon said:but for the fact that Python
stashes a reference to the module in (IIRC) sys.__modules__. And you
mess with *that* at your peril. ;-)
According to Python in a Nutshell, references are stored in the
dictionary sys.modules, but I'm not sure if it matters that it's not
__modules__ instead (unless that also exists).
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.