Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > namespace collisions

Reply
Thread Tools

namespace collisions

 
 
Jeremy Bowers
Guest
Posts: n/a
 
      02-17-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.

 
Reply With Quote
 
 
 
 
Will McGugan
Guest
Posts: n/a
 
      02-17-2005
Hi,

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?

TIA,

Will McGugan
 
Reply With Quote
 
 
 
 
John Lenton
Guest
Posts: n/a
 
      02-17-2005
On Thu, Feb 17, 2005 at 06:20:36PM +0000, Will McGugan wrote:
> Hi,
>
> 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?


local.util

is probably a convention worth starting

or you could go with

WilMcGugan.util

but ThatGetsOldFast.


--
John Lenton () -- Random fortune:
All my friends are getting married,
Yes, they're all growing old,
They're all staying home on the weekend,
They're all doing what they're told.

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (GNU/Linux)

iD8DBQFCFONYgPqu395ykGsRAvqbAJ4wiEJWQOaxBE0dLPvTgE K6vATJ6wCeOjSL
yBk5ZhTXd3RV4KP+8WghmV8=
=6DVB
-----END PGP SIGNATURE-----

 
Reply With Quote
 
wes weston
Guest
Posts: n/a
 
      02-17-2005
Will McGugan wrote:
> Hi,
>
> 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?
>
> TIA,
>
> Will McGugan

Will,
See http://www.boost.org/libs/python/doc...echniques.html

'about page 30 of google search. It gives an example
that should help.
wes

 
Reply With Quote
 
Dave Benjamin
Guest
Posts: n/a
 
      02-17-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
 
Reply With Quote
 
elbertlev@hotmail.com
Guest
Posts: n/a
 
      02-18-2005

John Lenton wrote:
> On Thu, Feb 17, 2005 at 06:20:36PM +0000, Will McGugan wrote:
> > Hi,
> >
> > 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?

>
> local.util
>
> is probably a convention worth starting
>
> or you could go with
>
> WilMcGugan.util
>
> but ThatGetsOldFast.
>
>
> --
> John Lenton () -- Random fortune:
> All my friends are getting married,
> Yes, they're all growing old,
> They're all staying home on the weekend,
> They're all doing what they're told.


I call modules like x_utils.py, where prefix x is assigned to a
particular pakage. In this case import statements look like:

import Company.repotrtools.e_excel as e_excel

or

from Company.repotrtools.e_excel import e_writer, e_reader

generally this are classes, not functions.

Newer had namespace collisions (yet

 
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
ARP Request Collisions on PIX-501 firewall Andrew Dancy Cisco 2 06-13-2007 11:47 AM
How should multiple (related) projects be arranged (structured) and configured so that they can share code, have a related package structure and enable proper unittesting, and ensuring no namespace collisions ToddLMorgan@gmail.com Python 14 04-21-2006 04:03 PM
late collisions chris-c Cisco 2 08-11-2004 03:37 AM
Collisions with Full-Duplex Jim Cisco 9 01-05-2004 02:41 PM
Cisco MC3810 with multiple ethernet collisions JFerri Cisco 1 11-19-2003 01:12 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57