General module name clash problem?

Discussion in 'Python' started by jipjip, Oct 19, 2007.

  1. jipjip

    jipjip Guest

    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
    jipjip, Oct 19, 2007
    #1
    1. Advertising

  2. 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
    Marc 'BlackJack' Rintsch, Oct 19, 2007
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jacob

    class name clash

    Jacob, Feb 6, 2004, in forum: Java
    Replies:
    14
    Views:
    829
    Larry Barowski
    Feb 10, 2004
  2. Martin Bless

    Q: distutils - name clash protection?

    Martin Bless, Jul 26, 2004, in forum: Python
    Replies:
    3
    Views:
    273
    Calvin Spealman
    Aug 2, 2004
  3. Olivier Vierlinck

    built-in function- module name clash

    Olivier Vierlinck, Sep 6, 2004, in forum: Python
    Replies:
    2
    Views:
    304
    Alex Martelli
    Sep 6, 2004
  4. George P
    Replies:
    3
    Views:
    680
    Alex Martelli
    Sep 11, 2004
  5. Joost
    Replies:
    3
    Views:
    253
    Gabriel Genellina
    Feb 5, 2007
Loading...

Share This Page