trouble with reload

Jean-Michel Pichavant jeanmichel at sequans.com
Fri Aug 14 05:27:39 EDT 2009


Dr. Phillip M. Feldman wrote:
> Actually, I've tried both of these, and I get (different) errors in both
> cases:
>
> In [1]: from mymath import *
>
> In [2]: reload(mymath)
> NameError: name 'mymath' is not defined
>
> In [3]: reload('mymath')
> TypeError: reload() argument must be module
>
>   
Please don't top post :o)

1/ Do not use the 'from <module> import *' form, unless you don't have 
any other choice, it will set in your namespace an undefined number of 
symbols, you may get some name collisions which usually lead to very 
nasty bugs.

import mymath
reload(mymath)

will do the trick.

If you are of those lazy coders you can write

import mymath as mm
reload(mm)
mm.aFunction()

If you are using a few functions and don't what to prefix them with the 
module name you can also write
import mymath
from mymath import func1, func2, func3

# reload the functions
reload(mymath)
func1 = mymath.func1
func2 = mymath.func2
func3 = mymath.func3

JM



More information about the Python-list mailing list