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

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

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. =?Utf-8?B?RnJhbmtfMDAwMDE=?=

    Controls.Add clash with Inner.Html?

    =?Utf-8?B?RnJhbmtfMDAwMDE=?=, Jul 14, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    2,384
    =?Utf-8?B?c29jaWV0b3BpYS5uZXQ=?=
    Jul 14, 2005
  2. Jacob

    class name clash

    Jacob, Feb 6, 2004, in forum: Java
    Replies:
    14
    Views:
    1,047
    Larry Barowski
    Feb 10, 2004
  3. Martin Bless

    Q: distutils - name clash protection?

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

    built-in function- module name clash

    Olivier Vierlinck, Sep 6, 2004, in forum: Python
    Replies:
    2
    Views:
    449
    Alex Martelli
    Sep 6, 2004
  5. George P
    Replies:
    3
    Views:
    896
    Alex Martelli
    Sep 11, 2004
  6. Joost
    Replies:
    3
    Views:
    417
    Gabriel Genellina
    Feb 5, 2007
  7. DeMarcus
    Replies:
    18
    Views:
    806
    Öö Tiib
    May 1, 2010
  8. Alex Gutteridge

    Name clash in C extension

    Alex Gutteridge, Jun 25, 2007, in forum: Ruby
    Replies:
    2
    Views:
    130
    Gabor Csardi
    Jul 3, 2007
Loading...