Changing the module not taking effect in calling module

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

    #1

    Changing the module not taking effect in calling module

    Hi,

    I've a module report.py having a set of funtions to open/close/write
    data to a log file. I invoke these functions from another module
    script.py.

    Whenever I'm changing something in report.py, I'm running the file
    (however, it has not effect). After that I'm running script.py again.
    However, the output is not taking effect.

    If I shut the IDLE interpreter and all the other files and then reopen
    again; and then run script.py, the output is taking effect.

    Is there any way to improve it? I'm new to Python.

    -Gopal.

  • Juho Schultz

    #2
    Re: Changing the module not taking effect in calling module

    Gopal wrote:[color=blue]
    > Hi,
    >
    > I've a module report.py having a set of funtions to open/close/write
    > data to a log file. I invoke these functions from another module
    > script.py.
    >
    > Whenever I'm changing something in report.py, I'm running the file
    > (however, it has not effect). After that I'm running script.py again.
    > However, the output is not taking effect.
    >
    > If I shut the IDLE interpreter and all the other files and then reopen
    > again; and then run script.py, the output is taking effect.
    >
    > Is there any way to improve it? I'm new to Python.
    >
    > -Gopal.
    >[/color]

    you could try "reload(module) " instead of "import module" or running the file.

    Comment

    • Mikael Olofsson

      #3
      Re: Changing the module not taking effect in calling module

      Gopal wrote:
      [color=blue]
      > I've a module report.py having a set of funtions to open/close/write
      > data to a log file. I invoke these functions from another module
      > script.py.
      >
      > Whenever I'm changing something in report.py, I'm running the file
      > (however, it has not effect). After that I'm running script.py again.
      > However, the output is not taking effect.
      >
      > If I shut the IDLE interpreter and all the other files and then reopen
      > again; and then run script.py, the output is taking effect.
      >
      > Is there any way to improve it? I'm new to Python.[/color]

      If I understand you correctly, you are importing your module report in
      script.py. If so, you need reload.

      When in IDLE, you have a python process running, in which you execute
      your program. The first time you run script.py after starting IDLE, your
      module report is imported from file. The next time you run script.py,
      there is already a module named report in memory. Then the corresponding
      file will not be executed again. Instead, the one in memory will be used.

      What I do when I am developing a module for a program is that I both
      import and reload the module in my main file. Once I think I am done
      developing, I remove the reload statement. So, in your script.py, I
      would write:

      import report
      reload(report)

      HTH
      /MiO

      Comment

      Working...