problems loading modules

Discussion in 'Python' started by Frank, Feb 5, 2007.

  1. Frank

    Frank Guest

    Hi,

    I have the following weird behavior when I load modules:


    Everything is fine.
    Traceback (most recent call last):

    Here it does not work.


    Now everything is back to normal.

    That means the order the modules are loaded matters! I would expect
    there is a problem with my installation because I guess this should
    normally be independent of the loaded modules.

    Here are my questions:
    1. Does anyone has this behavior too?

    2. How can I fix this problem?

    I use linux with fedora core 6 and python 2.4.4

    I appreciate any hint. Thanks!

    Frank
     
    Frank, Feb 5, 2007
    #1
    1. Advertisements

  2. Frank

    Robert Kern Guest

    numpy has a subpackage called random. You imported it when you did "from numpy
    import *".

    --
    Robert Kern

    "I have come to believe that the whole world is an enigma, a harmless enigma
    that is made terrible by our own mad attempt to interpret it as though it had
    an underlying truth."
    -- Umberto Eco
     
    Robert Kern, Feb 5, 2007
    #2
    1. Advertisements

  3. Here's a clue.

    ======<module 'numpy.random' from '/usr/lib/python2.4/site-packages/numpy/random/__init__.pyc'>
    =======

    Ganesan
     
    Ganesan Rajagopal, Feb 5, 2007
    #3
  4. Frank

    Ben Finney Guest

    "Don't do that, then."

    More specifically, 'from foo import *' is deprecated for exactly the
    reason you found here: you risk clobbering an existing name in the
    current namespace, and there's no way to determine that by looking at
    the code.

    Instead, import modules preserving a module namespace, which is the
    behaviour you get from 'import foo'. That way, all names remain
    explicit and you can see where you might be re-binding an existing
    name.
    <module 'numpy.random' from '/usr/lib/python2.4/site-packages/numpy/random/__init__.pyc'>

    Alternatively, if you want *specific* attributes from a module or
    package to be in the current namespace, import them explicitly by
    name; the same applied above, that you can see which names in
    particular are being re-bound.
    <module 'numpy.random' from '/usr/lib/python2.4/site-packages/numpy/random/__init__.pyc'>

    Again: don't use 'from foo import *', without knowing exactly why
    you're doing it. 'import foo' or 'from foo import bar' are always
    available, and usually better.
     
    Ben Finney, Feb 5, 2007
    #4
  5. Frank

    Frank Guest

    Thanks guys!
     
    Frank, Feb 6, 2007
    #5
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.