exec-function in Python 3.+

Dave Angel davea at ieee.org
Mon Nov 2 15:54:35 CET 2009


Hans Larsen wrote:
> Help!
>     I'm begginer in Python 3.+!
>     If i wih to update a module after an import and chages,
>     How could I do:
>     By "from imp import reload" and then reload(mymodule)
>     or how to use "exec(?)", it is mentoined in docs.
>     In Python ver. <3 reload(module) writes something back to interpretter!, 
> how about exec, which is a function?-:)
>     I,m thanking on the help!!
>
>
>   
I've never used reload() in 2.x or 3.x.  If I'm debugging interactively 
with the command line interpreter and I get to this point, I exit() and 
start the python interpreter again.  And if there was too much typing to 
waste by doing that, I write the code into another script, and run that 
from an IDE.  From most IDE's, you get a fresh chance every time you 
start a run.

I haven't found any reason to change this behavior.  So if you have a 
use-case, please elaborate.  And know that there are lots of traps in 
reloading a module, as it can't really eliminate all traces of being 
already run once.  It works for simple stuff, but you don't need it for 
simple stuff,...   And I guess I'm repeating myself.

DaveA



More information about the Python-list mailing list