exec-function in Python 3.+

H

Hans Larsen

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!!
 
J

Jon Clements

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!!

What makes you think you need to 'reload' a module. If you don't know
exactly what you're doing (by saying you're a beginner I'm guessing
not...), and aware of the consequences that can follow... I would say,
*don't*. There's too much to bite you in the rear (and not a blatant
bite from a lion, but rather a playful little kitten that then plays
cute and exudes a "moi?" expression).

Also, it may help others to post their thoughts if you tried to
describe why you think you want to go down this line, and what you're
trying to achieve.

Jon.
 
D

Dave Angel

Hans said:
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
 

Ask a Question

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.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,015
Latest member
AmbrosePal

Latest Threads

Top