A beginner's problem...

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

    A beginner's problem...

    Hello everyone,

    First, I have to say that Python is one of the coolest programing
    languages I have seen.
    And now for the problem (must be a silly one):
    When I import a module I have wrote, and then I find bugs, it seems that
    I can't import it again after a fix it. It always shows the same
    problem. I try del module but it doesn't work.
    (I use Python 2.4 with the ActivePython pack (PythonWin IDE)

    Solution anyone?

    Amir
  • Robert P. J. Day

    #2
    Re: A beginner's problem...

    On Wed, 15 Dec 2004, Amir Dekel wrote:
    [color=blue]
    > Hello everyone,
    >
    > First, I have to say that Python is one of the coolest programing languages I
    > have seen.
    > And now for the problem (must be a silly one):
    > When I import a module I have wrote, and then I find bugs, it seems that I
    > can't import it again after a fix it. It always shows the same problem. I try
    > del module but it doesn't work.
    > (I use Python 2.4 with the ActivePython pack (PythonWin IDE)
    >
    > Solution anyone?[/color]

    reload?

    rday

    Comment

    • Marc 'BlackJack' Rintsch

      #3
      Re: A beginner's problem...

      In <cpq6ov$q2s$1@n ews.iucc.ac.il> , Amir Dekel wrote:
      [color=blue]
      > When I import a module I have wrote, and then I find bugs, it seems that
      > I can't import it again after a fix it. It always shows the same
      > problem. I try del module but it doesn't work.
      > (I use Python 2.4 with the ActivePython pack (PythonWin IDE)
      >
      > Solution anyone?[/color]

      Yes -> help(reload)

      Ciao,
      Marc 'BlackJack' Rintsch

      Comment

      • DogWalker

        #4
        Re: A beginner's problem...

        "Marc 'BlackJack' Rintsch" <bj_666@gmx.net > said:
        [color=blue]
        >In <cpq6ov$q2s$1@n ews.iucc.ac.il> , Amir Dekel wrote:
        >[color=green]
        >> When I import a module I have wrote, and then I find bugs, it seems that
        >> I can't import it again after a fix it. It always shows the same
        >> problem. I try del module but it doesn't work.
        >> (I use Python 2.4 with the ActivePython pack (PythonWin IDE)
        >>
        >> Solution anyone?[/color]
        >
        >Yes -> help(reload)
        >
        >Ciao,
        > Marc 'BlackJack' Rintsch[/color]

        First, save the file using the check option (Ctl+Shift+C, iirc);
        Second, Fix any errors (attend to Status Bar);
        Third, press Reload button in Toolbar (or type command from File Menu).
        Four, assure that Status Bar indicates reload was successful.
        If still doesn't load correctly, quit PythonWin and start it again.


        Comment

        • Christian Ergh

          #5
          Re: A beginner's problem...

          DogWalker wrote:[color=blue]
          > "Marc 'BlackJack' Rintsch" <bj_666@gmx.net > said:
          >
          >[color=green]
          >>In <cpq6ov$q2s$1@n ews.iucc.ac.il> , Amir Dekel wrote:
          >>
          >>[color=darkred]
          >>>When I import a module I have wrote, and then I find bugs, it seems that
          >>>I can't import it again after a fix it. It always shows the same
          >>>problem. I try del module but it doesn't work.
          >>>(I use Python 2.4 with the ActivePython pack (PythonWin IDE)
          >>>
          >>>Solution anyone?[/color]
          >>
          >>Yes -> help(reload)
          >>
          >>Ciao,
          >> Marc 'BlackJack' Rintsch[/color]
          >
          >
          > First, save the file using the check option (Ctl+Shift+C, iirc);
          > Second, Fix any errors (attend to Status Bar);
          > Third, press Reload button in Toolbar (or type command from File Menu).
          > Four, assure that Status Bar indicates reload was successful.
          > If still doesn't load correctly, quit PythonWin and start it again.
          >[/color]
          Fifth, use the module unittest and write a test for your module. Just
          run the test to check your module and fix all errors, then import it
          into the larger sceme and see if everything works there. Most problems
          will appear in a good test, so you will not have the reimport issiue at all.
          Chris

          Comment

          • James Martin

            #6
            Re: A beginner's problem...

            Try deleting the Compiled Python File that was created during import --
            extension pyc. Then import again.

            It seems to me (I'm a novice too) that, when you import a module, Python
            automatically compiles it. Then when you import it later, the compiled
            version is imported if it exists.


            "Amir Dekel" <adekel@ort.org .il> wrote in message
            news:cpq6ov$q2s $1@news.iucc.ac .il...[color=blue]
            > Hello everyone,
            >
            > First, I have to say that Python is one of the coolest programing
            > languages I have seen.
            > And now for the problem (must be a silly one):
            > When I import a module I have wrote, and then I find bugs, it seems that
            > I can't import it again after a fix it. It always shows the same
            > problem. I try del module but it doesn't work.
            > (I use Python 2.4 with the ActivePython pack (PythonWin IDE)
            >
            > Solution anyone?
            >
            > Amir[/color]


            Comment

            • Mike Meyer

              #7
              Re: A beginner's problem...

              [Format recovered from top posting.]

              "James Martin" <sfyasha@POPwor ldnet.att.net> writes:[color=blue]
              >
              >
              > "Amir Dekel" <adekel@ort.org .il> wrote in message
              > news:cpq6ov$q2s $1@news.iucc.ac .il...[color=green]
              >> Hello everyone,
              >> First, I have to say that Python is one of the coolest programing
              >> languages I have seen.
              >> And now for the problem (must be a silly one):
              >> When I import a module I have wrote, and then I find bugs, it seems that
              >> I can't import it again after a fix it. It always shows the same
              >> problem. I try del module but it doesn't work.
              >> (I use Python 2.4 with the ActivePython pack (PythonWin IDE)
              >>
              >> Solution anyone?[/color]
              > Try deleting the Compiled Python File that was created during import --
              > extension pyc. Then import again.
              >
              > It seems to me (I'm a novice too) that, when you import a module, Python
              > automatically compiles it. Then when you import it later, the compiled
              > version is imported if it exists.[/color]

              It compares the dates on the .py file with the .pyc file, and
              recompiles the .py file if it's newer.

              Doing a second import will find the module in sys.modules and not
              bother looking in the file system. The solution is to reload(module)
              instead of import module.

              <mike
              --
              Mike Meyer <mwm@mired.or g> http://www.mired.org/home/mwm/
              Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.

              Comment

              • Amir Dekel

                #8
                Re: A beginner's problem...

                Mike Meyer wrote:[color=blue]
                >
                > Doing a second import will find the module in sys.modules and not
                > bother looking in the file system. The solution is to reload(module)
                > instead of import module.
                >
                > <mike[/color]
                What if I import using "from module import class"? It seems to me that I
                can't use reload then, or I just couldn't find the right syntax...

                Comment

                • Mike Meyer

                  #9
                  Re: A beginner's problem...

                  Amir Dekel <adekel@ort.org .il> writes:
                  [color=blue]
                  > Mike Meyer wrote:[color=green]
                  >> Doing a second import will find the module in sys.modules and not
                  >> bother looking in the file system. The solution is to reload(module)
                  >> instead of import module.
                  >> <mike[/color]
                  > What if I import using "from module import class"? It seems to me that
                  > I can't use reload then, or I just couldn't find the right syntax...[/color]

                  I'm pretty sure you'll have to import the module and reload it. "from
                  module import class" still puts the module in sys.modules, so trying
                  to import something from it again will find it in there.

                  <mike
                  --
                  Mike Meyer <mwm@mired.or g> http://www.mired.org/home/mwm/
                  Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.

                  Comment

                  • Nick Coghlan

                    #10
                    Re: A beginner's problem...

                    Amir Dekel wrote:[color=blue]
                    > Mike Meyer wrote:
                    >[color=green]
                    >>
                    >> Doing a second import will find the module in sys.modules and not
                    >> bother looking in the file system. The solution is to reload(module)
                    >> instead of import module.
                    >>
                    >> <mike[/color]
                    >
                    > What if I import using "from module import class"? It seems to me that I
                    > can't use reload then, or I just couldn't find the right syntax...[/color]

                    Correct. Using a non-from import is actually easier when experimenting, since
                    reload is easier to use.

                    If you have used a from-style import, you have to do this to force a reload of
                    the relevant class:

                    Py> from module import x
                    Py> # Do stuff
                    Py> import module
                    Py> reload(module)
                    Py> from module import x
                    Py> # We now have the updated version of x

                    Cheers,
                    Nick.

                    --
                    Nick Coghlan | ncoghlan@email. com | Brisbane, Australia
                    ---------------------------------------------------------------

                    Comment

                    Working...