reloading modules

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • aine_canby@yahoo.com

    #1

    reloading modules

    I'm using python.exe to execute my modules. I have a music.py module
    which contains my classes and a main.py module which uses these
    classes. In python.exe, I call "import main" to execute my program. The
    problem is that I have to close python and reopen it everytime i change
    music.py or main.py. What should I be doing.

    Thanks,

    Aine.

  • Dustan

    #2
    Re: reloading modules

    aine_canby@yaho o.com wrote:
    I'm using python.exe to execute my modules. I have a music.py module
    which contains my classes and a main.py module which uses these
    classes. In python.exe, I call "import main" to execute my program. The
    problem is that I have to close python and reopen it everytime i change
    music.py or main.py. What should I be doing.
    >
    Thanks,
    >
    Aine.
    >>import main
    ### Execution Occurs ###
    >># You go off to edit your module
    >>reload(main )
    ### Execution Occurs ###

    Comment

    • Dustan

      #3
      Re: reloading modules


      Dustan wrote:
      aine_canby@yaho o.com wrote:
      I'm using python.exe to execute my modules. I have a music.py module
      which contains my classes and a main.py module which uses these
      classes. In python.exe, I call "import main" to execute my program. The
      problem is that I have to close python and reopen it everytime i change
      music.py or main.py. What should I be doing.

      Thanks,

      Aine.
      >
      >import main
      ### Execution Occurs ###
      ># You go off to edit your module
      >reload(main)
      ### Execution Occurs ###
      I was obviously assuming that your module does something just by
      importing, which may or may not be the case. Either way, whenever a
      module may have been edited during a program's lifetime, it can be
      reloaded using the reload function.

      Comment

      • Frank Millman

        #4
        Re: reloading modules


        aine_canby@yaho o.com wrote:
        I'm using python.exe to execute my modules. I have a music.py module
        which contains my classes and a main.py module which uses these
        classes. In python.exe, I call "import main" to execute my program. The
        problem is that I have to close python and reopen it everytime i change
        music.py or main.py. What should I be doing.
        >
        Thanks,
        >
        Aine.
        Instead of calling 'import', use the 'imp' module and call
        'find_module' followed by 'load_module'. As the docs explain, one of
        the differences between this and 'import' is that it loads the module
        every time, even if it is already imported.

        HTH

        Frank Millman

        Comment

        • Kent Johnson

          #5
          Re: reloading modules

          Dustan wrote:
          aine_canby@yaho o.com wrote:
          >I'm using python.exe to execute my modules. I have a music.py module
          >which contains my classes and a main.py module which uses these
          >classes. In python.exe, I call "import main" to execute my program. The
          >problem is that I have to close python and reopen it everytime i change
          >music.py or main.py. What should I be doing.
          >>
          >Thanks,
          >>
          >Aine.
          >
          >>>import main
          ### Execution Occurs ###
          >>># You go off to edit your module
          >>>reload(mai n)
          ### Execution Occurs ###
          If you edit music.py you will have to
          import music
          reload(music)

          to get the new music module, then
          reload(main)

          to run again.

          You could just type
          python main.py
          at the command line each time you want to run, or use an editor that
          lets you run the program from within the editor.

          Kent

          Comment

          Working...