namespace collisions

Jeremy Bowers jerf at jerf.org
Thu Feb 17 10:03:14 EST 2005


On Thu, 17 Feb 2005 18:20:36 +0000, Will McGugan wrote:
> I'm accumulating a number of small functions, which I have sensibly put 
> in a single file called 'util.py'. But it occurs to me that with such a 
> generic name it could cause problems with other modules not written by 
> myself. Whats the best way of handling this? If I put it in a common 
> location in my Python path, should I call it willsutil.py?

Yes, something like that would be best. Two modules with the same name can
cause problems because once one is imported, the other will never be;
'import' just returns the first out of the cache.

Looking on my system, I see 6 "utils.py" files; one in the xmlproc parser,
two in twisted, one in docutils, one in a program called "sgmltools", and
one in the xblproc parser in Jython, which I didn't even know I had
installed(!). While I don't think you should have a problem because those
are submodules (that is, you can't 'import utils', you have to 'import
docutils.utils' and that doesn't create a 'utils' module), I'd say that
in general, that's a scary enough name that you are likely to encounter
trouble later.




More information about the Python-list mailing list