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

Discussion in 'Python' started by bsneddon, Oct 8, 2009.

  1. bsneddon

    bsneddon Guest

    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
     
    bsneddon, Oct 8, 2009
    #1
    1. Advertising

  2. bsneddon

    Simon Forman Guest

    On Thu, Oct 8, 2009 at 9:47 AM, bsneddon <> 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
     
    Simon Forman, Oct 8, 2009
    #2
    1. Advertising

  3. bsneddon

    Dave Angel Guest

    bsneddon 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.
    > <snip>
    >
    >

    Caching (not cashing) doesn't come into play here. Objects are kept as
    long as there is a reference to them somewhere. So renamed functions
    can still exist under their old name, since nobody has reused the name
    for something newer.

    I'm not familiar with PythonWin. But if it's like the standard python
    interpreter, where you use import at the command line to load a module,
    then I can comment on it.

    Doing a second import on the same module will not look at the disk file
    at all. To get it to re-read the source code, you need reload(). And
    reload() doesn't really do everything you'd expect. In some cases it
    cannot (for example, references to external DLL's). So there are
    frequently remnants of the earlier version of things lying around.

    If this is really an interpreter environment, I'd exit the environment
    and start it again. If it's more like a GUI (like Komodo, which I
    use), then the gui will kill the old interpreter and start another one
    when you say "exit" and "run". Then you have nothing left of the old
    version of the module, and can start from scratch.

    As Simon said, you should read about reload(), and its caveats:
    http://docs.python.org/library/functions.html#reload



    DaveA
     
    Dave Angel, Oct 8, 2009
    #3
  4. bsneddon

    Guest

    On Oct 8, 2:12 pm, Dave Angel <> wrote:
    > bsneddon 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.
    > > <snip>

    >
    > Caching (not cashing) doesn't come into play here.  Objects are kept as
    > long as there is a reference to them somewhere.  So renamed functions
    > can still exist under their old name, since nobody has reused the name
    > for something newer.
    >
    > I'm not familiar with PythonWin.  But if it's like the standard python
    > interpreter, where you use import at the command line to load a module,
    > then I can comment on it.
    >
    > Doing a second import on the same module will not look at the disk file
    > at all.  To get it to re-read the source code, you need reload().  And
    > reload() doesn't really do everything you'd expect.  In some cases it
    > cannot (for example, references to external DLL's).  So there are
    > frequently remnants of the earlier version of things lying around.
    >
    > If this is really an interpreter environment, I'd exit the environment
    > and start it again.   If it's more like a GUI (like Komodo, which I
    > use), then the gui will kill the old interpreter and start another one
    > when you say "exit" and "run".   Then you have nothing left of the old
    > version of the module, and can start from scratch.
    >
    > As Simon said, you should read about reload(), and its caveats:
    >    http://docs.python.org/library/functions.html#reload
    >
    > DaveA


    Thanks I have looked at reload now. It seem pythonWin tries to use
    reload
    when doing an import. I think I need to do a little more reading on
    PythonWin.

    Bill
     
    , Oct 8, 2009
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Shuo Xiang

    Stack space, global space, heap space

    Shuo Xiang, Jul 9, 2003, in forum: C Programming
    Replies:
    10
    Views:
    2,936
    Bryan Bullard
    Jul 11, 2003
  2. stephan
    Replies:
    0
    Views:
    449
    stephan
    Jul 30, 2003
  3. Christian Seberino
    Replies:
    21
    Views:
    1,718
    Stephen Horne
    Oct 27, 2003
  4. Ian Bicking
    Replies:
    2
    Views:
    1,053
    Steve Lamb
    Oct 23, 2003
  5. cy

    Client side cashing.

    cy, Jun 16, 2004, in forum: Javascript
    Replies:
    2
    Views:
    102
    Vincent van Beveren
    Jun 17, 2004
Loading...

Share This Page