Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > General module name clash problem?

Reply
Thread Tools

General module name clash problem?

 
 
jipjip
Guest
Posts: n/a
 
      10-19-2007
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
 
Reply With Quote
 
 
 
 
Marc 'BlackJack' Rintsch
Guest
Posts: n/a
 
      10-19-2007
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
stlib name clash when using python as ASP language Joost Python 3 02-05-2007 10:55 PM
package module import name clash with global package George P Python 3 09-11-2004 01:19 PM
built-in function- module name clash Olivier Vierlinck Python 2 09-06-2004 10:13 AM
Q: distutils - name clash protection? Martin Bless Python 3 08-02-2004 08:07 PM
class name clash Jacob Java 14 02-10-2004 08:55 AM



Advertisments