Proposal: add sys to __builtins__

Sybren Stuvel sybrenUSE at YOURthirdtower.com.imagination
Mon Sep 5 15:12:05 CEST 2005


Rick Wotnaz enlightened us with:
> That is, a reference to xxx.func(), without a previous import of xxx
> *could* be resolvable automatically, at least for those modules that
> can be found in a standard location.

-1 on that one. If I want to use a module, I'll write an import
statement for it. Those import statements make it very easy to get an
overview of the modules in use.

Automatically importing modules has the counter-effect of not
generating errors when they should be. Someone could have a class
stored in a variable 'os' and call a function on it. If this person
forgets to assign a value to 'os', an error message should be given
instead of importing the 'os' module.

Another issue is speed. If every reference in the form xxx.yyy has to
trigger an import when xxx isn't known, it will probably slow down
programs quite badly.

A programming language should not be ambiguous. The choice between
importing a module and calling a function should not depend on the
availability of a (local) variable.

> I don't see why it would be impossible to make that happen
> automatically, provided the module to be imported was recognized
> (through some undefined magic).

The question is not if it's possible or not - in principle, everything
is possible. The question is if it is desirable.

> A developer would most likely want to set up the imports properly,
> and to know when they were not correctly set up instead of having
> Python fix things quietly.

Yep.

> But *could* it be done? I'd think so. 

Sure.

Sybren
-- 
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself? 
                                             Frank Zappa



More information about the Python-list mailing list