Proposal: add sys to __builtins__

Rick Wotnaz desparn at wtf.com
Thu Sep 1 16:35:32 EDT 2005


Michael Hoffman <cam.ac.uk at mh391.invalid> wrote in
news:df7jlu$1te$1 at gemini.csx.cam.ac.uk: 

> What would people think about adding sys to __builtins__ so that
> "import sys" is no longer necessary? This is something I must
> add to every script I write that's not a one-liner since they
> have this idiom at the bottom:
> 
> if __name__ == "__main__":
>      sys.exit(main(sys.argv[1:]))
> 
> Additionally, the necessity of "import sys" makes some
> one-liners a little more unwieldy than they should be--it is
> surely the module I am missing the most in one-liners. For
> example, with this proposal, this inelegant one-liner:
> 
> $ python -c "import sys; print
> ''.join(sorted(sys.stdin.readlines()))" 
> 
> could be replaced by:
> 
> $ python -c "print ''.join(sorted(sys.stdin.readlines()))"
> 
> Since sys is surely the most commonly used module (it is
> imported in 108 of 188 Python 2.4 stdlib modules on my system,
> and certainly more than any other module), I would hope few
> people would be affected by a namespace collision.
> 
> Other languages (e.g. C#) always make their system namespace
> available without needing a special import.
> 
> In short, given the wide use of sys, its unambiguous nature, and
> the fact that it really is built-in already, although not
> exposed as such, I think we would be better off if sys were
> always allowed even without an import statement.

+1 here. As far as I'm concerned, both os and sys could be special-
cased that way. That said, I would guess the likelihood of that 
happening is 0. 

-- 
rzed



More information about the Python-list mailing list