problems loading modules

F

Frank

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
 
R

Robert Kern

Frank said:
Hi,

I have the following weird behavior when I load modules:


8

Everything is fine.

Traceback (most recent call last):
File "<stdin>", line 1, in ?
AttributeError: 'module' object has no attribute 'randrange'

Here it does not work.

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
 
B

Ben Finney

Frank said:
Everything is fine.

Traceback (most recent call last):


Here it does not work.

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

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top