[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: Fix the current test suite

From: Greg Stein <gstein_at_lyra.org>
Date: 2001-05-09 02:52:19 CEST

On Tue, May 08, 2001 at 05:46:12PM -0500, Ben Collins-Sussman wrote:
>...
> > +import sys
> ...
> > - exit(1)
> > + sys.exit(1)
>
> Is the "sys" module not automatically loaded in all Python
> distributions? To be safe, must we always explicitly import it?
> (gstein?)

Python never monkeys with your namespace behind your back. If you want a
name in your namespace, then you must put it there. Thus, you need to do the
"import sys" to make the "sys" available.

[ yes, the module was probably loaded by something else, but that doesn't
  magically create names in random namespaces (such as that of your script) ]

In general, Python takes great care with not polluting namespaces. That is
why the form:

    from some_module import *

Is so frowned upon. Who knows what names will be created in your namespace?
"Proper" style is to just do "import some_module" and then refer to the
various symbols using "some_module.some_name".

As an anology, in C/C++, doing #include <header.h> will inject all kinds of
symbols into your namespace. This is why we have the SVN_ and svn_ prefixes
-- it's a way to prevent conflicts. In Python, we'd be using the module
namespaces for protection.

Cheers,
-g

-- 
Greg Stein, http://www.lyra.org/
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Sat Oct 21 14:36:30 2006

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.