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 5 1537
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
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.
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
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 (jo**@grulic.org.ar) -- 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-----
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 (jo**@grulic.org.ar) -- 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 :) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Randy Yates |
last post by:
I've seen this creep into c++ and have never heard of it. It apparently
has something to do with the standard C++ library header files (e.g., <string>,
<fstream>, etc.). Any illunination?
--
% ...
|
by: Kevin Newman |
last post by:
I've been toying with a namespace manager, and wanted to get some input.
So what do you think?
if (typeof com == 'undefined') var com = {};
if (!com.unFocus) com.unFocus = {};
...
|
by: ad |
last post by:
Is there any difference about namespace between VB.NET and C#.
All functions in c# must include in a namespace.
Why I can't find namespace in the files .vb .
How VB.NET implement the...
|
by: toolmaster |
last post by:
Since many of the modern computer languages have built-in namespace
features, I can't understand why not add this feature into standard C.
I've heard many people complain of the lacking of...
|
by: ToddLMorgan |
last post by:
Summary:
How should multiple (related) projects be arranged (structured) and
configured so that the following is possible:
o Sharing common code (one of the projects would be a "common"
project...
|
by: Pep |
last post by:
Is it best to include the code "using namespace std;" in the source or
should each keyword in the std namespace be qualified by the namespace tag,
such as
std::cout << "using std namespace" <<...
|
by: patrick |
last post by:
Why do some code listings for learning C++ have the entire namespace
std being used while others just specify the parts they want to use?
|
by: Jess |
last post by:
Hello,
I learned that we are not allowed to add any new templates or classes
or functions or anything else to std namespace. Does it mean that
"std" can never be extended? I can't even add any...
|
by: bb |
last post by:
Hi,
Is there any specific reason(s) that there is only one namespace
'std' in the standard library?
e.g. namespaces are not really independent, name collisions etc.
Should one consider not...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
| |