namespace collisions
Dave Benjamin
ramen at lackingtalent.com
Thu Feb 17 15:36:28 EST 2005
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?
I find that it's beneficial in the long run to create a package for your
project. This will insure you against name collisions in general, should
you later need to combine projects::
import myproject.util
myproject.util.myhandyfunction()
etc.
The potential downside is that if you really need to reuse util.py in
multiple projects, you'll have to copy the file to each package, or
create a central package that the other projects' packages link to. But
it's been my experience that the type of stuff that goes in "util"
modules is pretty miscellaneous in nature, and not as reusable as it
seems. Not worth creating additional dependencies, anyway.
There's really no one right answer to your question, but I've been
(mildly) bitten by naming collisions, and as a result I use packages for
every project now.
Dave
More information about the Python-list
mailing list