General module name clash problem?

J

jipjip

Hello all,
just new to python..

Suppose i have a directory only with an empty file "pickle.py".
In this directory i start the python interpreter and say:
What happens?
I get an error message:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.5/site-packages/pygame/__init__.py", line 147,
in <module>
try: import pygame.surfarray
File "/usr/lib/python2.5/site-packages/Numeric/Numeric.py", line 536,
in <module>
class Unpickler(pickle.Unpickler):
AttributeError: 'module' object has no attribute 'Unpickler'

Why?
Because pygame needs a module namend "pickle.py"!
The first location python searches is my directory, so
the library module "pickle.py" is overwritten with my "pickle.py".

The cause of this error is not that i import 2 different modules with
the same name, it's only because there is a file in my directory with
the same name of a module somewhere in the imported module tree.

I mean, this is a general problem.
Must i look for every module that gets importet for not clashing
with my module files residing in the calling directory?

Is the python package system insufficient, is there something wrong with
my opinions or do i need a "gotcha"?

Thank's in advance,
jipjip
 
M

Marc 'BlackJack' Rintsch

I mean, this is a general problem.
Must i look for every module that gets importet for not clashing
with my module files residing in the calling directory?
Yes.

Is the python package system insufficient, is there something wrong with
my opinions or do i need a "gotcha"?

The package system is not insufficient but could solve your problem
actually. Don't put all your modules simply in the same directory but in a
package so that your `whatever.pickle` does not clash with the standard
`pickle` anymore.

Ciao,
Marc 'BlackJack' Rintsch
 

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

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top