IDLE confusion

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • MrBlueSky

    #1

    IDLE confusion

    Hi, I'm trying to use IDLE to develop My First Python App and my head
    hurts...

    I've a file called spalvi.py with this in it:
    from Test import *
    firstTest("Mike ")

    And a file called Test.py with this in it:
    def firstTest(name) :
    print "Yo",name

    I open spalvi.py with IDLE and Run it. It says "Yo Mike".
    I use the File menu to open Test.py and change the message from "Yo" to
    "Hi".
    I Run it again.... it still says "Yo Mike" :-(
    I close everything down, open spalvi.py with IDLE and Run it again. It
    says "Hi Mike".

    So I'm obviously not using IDLE in the "right" way. But what *is* the
    "right" way, when you're trying to develop using several source files?

    John

  • Claudio Grondi

    #2
    Re: IDLE confusion

    MrBlueSky wrote:[color=blue]
    > Hi, I'm trying to use IDLE to develop My First Python App and my head
    > hurts...
    >
    > I've a file called spalvi.py with this in it:
    > from Test import *
    > firstTest("Mike ")
    >
    > And a file called Test.py with this in it:
    > def firstTest(name) :
    > print "Yo",name
    >
    > I open spalvi.py with IDLE and Run it. It says "Yo Mike".
    > I use the File menu to open Test.py and change the message from "Yo" to
    > "Hi".
    > I Run it again.... it still says "Yo Mike" :-(
    > I close everything down, open spalvi.py with IDLE and Run it again. It
    > says "Hi Mike".
    >
    > So I'm obviously not using IDLE in the "right" way. But what *is* the
    > "right" way, when you're trying to develop using several source files?
    >
    > John
    >[/color]
    You need some deeper understanding of what import does and what happens
    when you import again (after the library files have changed).
    Try in the IDLE menu [Shell] "Restart Shell" (Ctrl+F6) each time you
    have changed something in your files - this "resets" anything previously
    imported, which stays the same way otherwise.

    Claudio

    Comment

    • Christophe

      #3
      Re: IDLE confusion

      Claudio Grondi a écrit :[color=blue]
      > MrBlueSky wrote:
      >[color=green]
      >> Hi, I'm trying to use IDLE to develop My First Python App and my head
      >> hurts...
      >>
      >> I've a file called spalvi.py with this in it:
      >> from Test import *
      >> firstTest("Mike ")
      >>
      >> And a file called Test.py with this in it:
      >> def firstTest(name) :
      >> print "Yo",name
      >>
      >> I open spalvi.py with IDLE and Run it. It says "Yo Mike".
      >> I use the File menu to open Test.py and change the message from "Yo" to
      >> "Hi".
      >> I Run it again.... it still says "Yo Mike" :-(
      >> I close everything down, open spalvi.py with IDLE and Run it again. It
      >> says "Hi Mike".
      >>
      >> So I'm obviously not using IDLE in the "right" way. But what *is* the
      >> "right" way, when you're trying to develop using several source files?
      >>
      >> John
      >>[/color]
      > You need some deeper understanding of what import does and what happens
      > when you import again (after the library files have changed).
      > Try in the IDLE menu [Shell] "Restart Shell" (Ctrl+F6) each time you
      > have changed something in your files - this "resets" anything previously
      > imported, which stays the same way otherwise.
      >
      > Claudio[/color]

      And I though that "bug" was fixed already :) Try to use something else
      than IDLE for your code editing. Use Scite for example.

      Scintilla, SciTE, Editing Component, Text Editor

      Comment

      • Terry Reedy

        #4
        Re: IDLE confusion


        "Christophe " <chris.cavalari a@free.fr> wrote in message
        news:446991de$0 $7690$626a54ce@ news.free.fr...[color=blue]
        > Try in the IDLE menu [Shell] "Restart Shell" (Ctrl+F6) each time you
        > have changed something in your files - this "resets" anything previously
        > imported, which stays the same way otherwise.[/color]

        And I though that "bug" was fixed already :)

        On my system, the current 2.4.3 version of Python+IDLE *does* auto restart
        with each run (F5). So either the OP is using a much older version (did
        not specify) or the respondant mis-diagnosed the problem.

        tjr



        Comment

        • taleinat@gmail.com

          #5
          Re: IDLE confusion

          This isn't really an IDLE issue, it's a Python feature which needs to
          be understood.

          In Python, once you've imported a module once, importing it again is
          ignored. This works fine under the assumption that modules don't change
          during a single Python session. However, when you're developing a
          module this isn't true, and a workaround for this mechanism is needed.


          The safest way to go is to start a new Python session.

          In the IDLE interpreter ("Shell" window) you can do this from the Shell
          menu. Running a module from an IDLE editor window (Run->Run Module)
          will also restart the interpreter.

          Notice, however, that these will only work if IDLE has a sub-process
          for the interpreter! If not, the Shell menu won't exist, and Run Module
          won't restart the interpreter.

          On Windows, opening IDLE by right-clicking a file and choosing 'Edit
          with IDLE' will cause it to open without a subprocess.



          If you change a module and want to use the newer version in the same
          Python session, use the built-in 'reload' function:

          import Test
          reload(Test)

          Notice that if you use the 'from <module> import ...' syntax, you need
          to import the module itself (i.e. import <module>) before you can
          reload it.

          I advise to use this with care, as things can get quite confusing after
          a few reloads...

          Comment

          • Christophe

            #6
            Re: IDLE confusion

            Terry Reedy a écrit :[color=blue]
            > "Christophe " <chris.cavalari a@free.fr> wrote in message
            > news:446991de$0 $7690$626a54ce@ news.free.fr...
            >[color=green]
            >>Try in the IDLE menu [Shell] "Restart Shell" (Ctrl+F6) each time you
            >>have changed something in your files - this "resets" anything previously
            >>imported, which stays the same way otherwise.[/color]
            >
            >
            > And I though that "bug" was fixed already :)
            >
            > On my system, the current 2.4.3 version of Python+IDLE *does* auto restart
            > with each run (F5). So either the OP is using a much older version (did
            > not specify) or the respondant mis-diagnosed the problem.[/color]

            I was looking at some idlefork info not long ago and I found something
            which might get those different behaviours with a recent version of idle
            : if idle cannot open it's RPC socket, it'll execute all python code in
            it's own interpreter. There's an option for that in fact.

            Comment

            • Scott David Daniels

              #7
              Re: IDLE confusion

              Christophe wrote:[color=blue]
              > Terry Reedy a écrit :[color=green]
              >> "Christophe " <chris.cavalari a@free.fr> wrote in message
              >> news:446991de$0 $7690$626a54ce@ news.free.fr...
              >>[color=darkred]
              >>> Try in the IDLE menu [Shell] "Restart Shell" (Ctrl+F6) each time you
              >>> have changed something in your files - this "resets" anything previously
              >>> imported, which stays the same way otherwise.[/color]
              >>
              >>
              >> And I though that "bug" was fixed already :)
              >>
              >> On my system, the current 2.4.3 version of Python+IDLE *does* auto
              >> restart with each run (F5). So either the OP is using a much older
              >> version (did not specify) or the respondant mis-diagnosed the problem.[/color]
              >
              > I was looking at some idlefork info not long ago and I found something
              > which might get those different behaviours with a recent version of idle
              > : if idle cannot open it's RPC socket, it'll execute all python code in
              > it's own interpreter. There's an option for that in fact.[/color]
              The option (for those playing along) is '-n'
              So:
              Windows: command is: \python24\Lib\i dlelib\idle.pyw -n
              OS-X: command is: pythonw ?/python24/Lib/idlelib/idle.pyw -n
              Linux & such: python ?/python24/Lib/idlelib/idle.pyw -n
              (I think these don't
              distinguish python & pythonw)

              It is useful if you are having some socket-to-self issues typically
              caused by over-conservative firewall settings, because no socket
              is allocated for communication.

              It is also useful for experimenting with Tkinter, because a Tkinter
              display loop is already running, so you can see the effects of your
              Tkinter commands as they are entered.

              --Scott David Daniels
              scott.daniels@a cm.org

              Comment

              Working...