Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is there an equivalent __reload__ function as to __import__?

I only know the module name during runtime, and as such this is how it looks like:-

a = 'mymodule'
__import__(a)

but along the way, when mymodule.py is changed, i wanna reload it again. is there a command like

__reload__(a)

?

like image 955
lionel319 Avatar asked Oct 27 '25 13:10

lionel319


1 Answers

Yes. It's reload(module). See the python modules documentation (section 6.1) and the library builtin functions reference.

The argument is a module object, not a string so you must import it first.

mymodule = __import__('mymodule')
reload(mymodule)
like image 148
SpliFF Avatar answered Oct 30 '25 03:10

SpliFF



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!