A beginner's problem...

Discussion in 'Python' started by Amir Dekel, Dec 15, 2004.

  1. Amir Dekel

    Amir Dekel Guest

    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
     
    Amir Dekel, Dec 15, 2004
    #1
    1. Advertising

  2. On Wed, 15 Dec 2004, Amir Dekel wrote:

    > 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?


    reload?

    rday
     
    Robert P. J. Day, Dec 15, 2004
    #2
    1. Advertising

  3. In <cpq6ov$q2s$>, Amir Dekel wrote:

    > 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?


    Yes -> help(reload)

    Ciao,
    Marc 'BlackJack' Rintsch
     
    Marc 'BlackJack' Rintsch, Dec 15, 2004
    #3
  4. Amir Dekel

    DogWalker Guest

    "Marc 'BlackJack' Rintsch" <> said:

    >In <cpq6ov$q2s$>, Amir Dekel wrote:
    >
    >> 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?

    >
    >Yes -> help(reload)
    >
    >Ciao,
    > Marc 'BlackJack' Rintsch


    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.
     
    DogWalker, Dec 16, 2004
    #4
  5. DogWalker wrote:
    > "Marc 'BlackJack' Rintsch" <> said:
    >
    >
    >>In <cpq6ov$q2s$>, Amir Dekel wrote:
    >>
    >>
    >>>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?

    >>
    >>Yes -> help(reload)
    >>
    >>Ciao,
    >> Marc 'BlackJack' Rintsch

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

    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
     
    Christian Ergh, Dec 16, 2004
    #5
  6. Amir Dekel

    James Martin Guest

    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" <> wrote in message
    news:cpq6ov$q2s$...
    > 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
     
    James Martin, Dec 18, 2004
    #6
  7. Amir Dekel

    Mike Meyer Guest

    [Format recovered from top posting.]

    "James Martin" <> writes:
    >
    >
    > "Amir Dekel" <> wrote in message
    > news:cpq6ov$q2s$...
    >> 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?

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


    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 <> http://www.mired.org/home/mwm/
    Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
     
    Mike Meyer, Dec 18, 2004
    #7
  8. Amir Dekel

    Amir Dekel Guest

    Mike Meyer wrote:
    >
    > 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

    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...
     
    Amir Dekel, Dec 18, 2004
    #8
  9. Amir Dekel

    Mike Meyer Guest

    Amir Dekel <> writes:

    > Mike Meyer wrote:
    >> 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

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


    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 <> http://www.mired.org/home/mwm/
    Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
     
    Mike Meyer, Dec 18, 2004
    #9
  10. Amir Dekel

    Nick Coghlan Guest

    Amir Dekel wrote:
    > Mike Meyer wrote:
    >
    >>
    >> 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

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


    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 | | Brisbane, Australia
    ---------------------------------------------------------------
    http://boredomandlaziness.skystorm.net
     
    Nick Coghlan, Dec 18, 2004
    #10
    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. Larry Smith

    Trivial resources problem (beginner)

    Larry Smith, Oct 2, 2003, in forum: ASP .Net
    Replies:
    3
    Views:
    528
    Scott Manson
    Oct 2, 2003
  2. =?Utf-8?B?S3VydCBTY2hyb2VkZXI=?=

    No Class at ALL!!! beginner/beginner question

    =?Utf-8?B?S3VydCBTY2hyb2VkZXI=?=, Feb 2, 2005, in forum: ASP .Net
    Replies:
    7
    Views:
    634
    =?Utf-8?B?S3VydCBTY2hyb2VkZXI=?=
    Feb 3, 2005
  3. Rensjuh
    Replies:
    7
    Views:
    1,022
    Mabden
    Sep 2, 2004
  4. Toni
    Replies:
    3
    Views:
    2,267
    msnews.microsoft.com
    Jul 29, 2006
  5. william nelson

    Beginner's Beginner

    william nelson, Apr 11, 2011, in forum: Ruby
    Replies:
    7
    Views:
    245
    7stud --
    Apr 12, 2011
Loading...

Share This Page