Gabriel Genellina wrote:
[snip]
One way to avoid name clashes would be to put the entire standard
library under a package; a program that wants the standard re
module would write "import std.re" instead of "import re", or
something similar. Every time the std package is suggested, the
main argument against it is backwards compatibility.

You could do it in a backwards compatible way, by adding the std
package directory into the path.

Unfortunately you can't, at least not without some special treatment
of the std package. One of the undocumented rules of the import
system is that you must not have more than one way to refer to the
same module (in this case, std.re and re). Suppose someone imports
std.re; an entry in sys.modules with that name is created. Later
someone imports re; as there is no entry in sys.modules with such
name, the re module is imported again, resulting in two module
instances, darkness, weeping and the gnashing of teeth :) (I'm sure
you know the problem: it's the same as when someone imports the main
script as a module, and gets a different module instance because the
"original" is called __main__ instead).

Couldn't the entry in sys.modules be where the module was found, so that
if 're' was found in 'std' then the entry is 'std.re' even if the import
said just 're'?
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to