Reloading function obtained via 'from xxx import yyy'

Benjamin Kaplan benjamin.kaplan at case.edu
Sat May 24 08:21:27 EDT 2008


On Fri, May 23, 2008 at 3:40 PM, Joel Koltner <zapwireDASHgroups at yahoo.com>
wrote:

> How do I get Python to correctly re-load this function definition?
>
> In test.py:
>
> def testFunc():
>    print 'My testFunc!'
>
> I execute...
>
> >>> from test import testFunc
> >>> testFunc()
> My testFunc!
>
> Fine... now I change test.py to:
>
> def testFunc():
>    print 'Modified testFunc!'
>
> ...and I'd like to reload testFunc.  How do I do so?  'from test import
> testFunc' keeps the old definition around, and 'reload test' of course
> doesn't
> work becayse I didn't use 'import test' in the first place.
>

"Namespaces are one honking great idea -- let's do more of those!"

If you don't want to have to type out the full name every time just do
"import test as t". That makes it only 2 extra characters to type. If you
don't put everything in the same namespace, you don't have to worry about
clashing.

>
> Thanks for the help,
> ---Joel
>
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20080524/0c67b9c6/attachment-0001.html>


More information about the Python-list mailing list