Cashing in PythonWin name space?... seems unexpected to me

Simon Forman sajmikins at gmail.com
Thu Oct 8 12:45:44 EDT 2009


On Thu, Oct 8, 2009 at 9:47 AM, bsneddon <bsneddon at yahoo.com> wrote:
> I saw an issue  on winXP  box not connected to internet yesterday,
> where i was running
> a script in the interactive window on PythonWin .   I would modify the
> script save and
> import and was still running the old version.  I did that several
> times with same result.
> I even renamed the function and it showed up but ran the old script.
> Very strange.
>
> I tried reproducing this morning on a machine that is connected to
> internet was unable to
> but did get the behavior below that I do not understand.
>
> created module named spam with this code.
> def ello():
>    print "Your father smells of elderberrys"
>
> Here is expert for interactive window to explain the issue: question
> is below.
>
> PythonWin 2.6 (r26:66721, Oct  2 2008, 11:35:03)
> I
>
>
> renamed ello to insult and re-imported.
>
>>>> dir(spam)
> [clip.. 'ello', 'insult']
>
> ello still exist in namespace an runs ... not so strange
>>>> spam.ello()
> Your father smells of elderberrys
>
>>>> del(spam)
> delete spam and it no longer runs as expected.
>
> modify insult to this:
> def insult():
>    print "Your father smells of elderberrys/n and your mother was a
> kiniggit"
>
> Q.
> on re-importing spam ello is back and continues to run.   I did note
> expect this to be the
> case.  Can someone explain what is happening?
>
>>>> dir(spam)
> [clip..., 'ello', 'insult']
>>>> spam.ello()
> Your father smells of elderberrys
>>>> spam.insult()
> Your father smells of elderberrys/n and your mother was a kiniggit
>>>>
>
>
> Thanks for your help.
>
> Bill Sneddon

The reload() function might be what you need:
http://docs.python.org/library/functions.html#reload

HTH,
~Simon



More information about the Python-list mailing list