471,306 Members | 936 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,306 software developers and data experts.

General module name clash problem?

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:
>>import pygame
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
Oct 19 '07 #1
1 1795
On Fri, 19 Oct 2007 13:09:22 +0200, jipjip wrote:
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
Oct 19 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Glenn Reed | last post: by
8 posts views Thread by Felix Wiemann | last post: by
2 posts views Thread by Olivier Vierlinck | last post: by
9 posts views Thread by Darren Dale | last post: by
1 post views Thread by gcook | last post: by
2 posts views Thread by Deepa K | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.