本文介绍了建议:将sys添加到__builtins__的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 人们会怎样考虑将sys添加到__builtins__以便 " import sys"不再需要?这是我必须添加的内容 我写的每个脚本都不是单行,因为他们有这个成语 在底部: if __name__ ==" __ main __": sys.exit(main(sys.argv [1:])) 此外,进口系统的必要性让一些单线球员比他们应该更加笨拙 - 这肯定是我在单线上缺少最多的模块。例如,有了这个提议,这个 不优雅的单行: $ python -c" import sys; print''''。join(sorted(sys.stdin.readlines()))" 可以替换为: $ python -c" print''''。join(sorted(sys.stdin.readlines()))" 因为sys肯定是最常用的模块(它在我的系统中导入了108个2.4 2.4 stdlib模块的,当然还有超过 任何其他模块),我希望很少有人会受到 命名空间冲突。 其他语言(例如C#)总是使他们的系统命名空间可用 而不需要特殊的导入。 /> 简而言之,鉴于sys的广泛使用,其明确的性质,以及它实际上已经内置的事实,尽管没有暴露出来,我认为即使没有 导入声明,如果系统总是被允许,我们会更好。 - Michael Hoffman What would people think about adding sys to __builtins__ so that"import sys" is no longer necessary? This is something I must add toevery script I write that''s not a one-liner since they have this idiomat the bottom: if __name__ == "__main__":sys.exit(main(sys.argv[1:])) Additionally, the necessity of "import sys" makes some one-liners alittle more unwieldy than they should be--it is surely the module I ammissing the most in one-liners. For example, with this proposal, thisinelegant 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 108of 188 Python 2.4 stdlib modules on my system, and certainly more thanany other module), I would hope few people would be affected by anamespace collision. Other languages (e.g. C#) always make their system namespace availablewithout needing a special import. In short, given the wide use of sys, its unambiguous nature, and thefact that it really is built-in already, although not exposed as such, Ithink we would be better off if sys were always allowed even without animport statement.--Michael Hoffman推荐答案 pytho n -cimport sys; print''''。join(sorted(sys.stdin.readlines()))" 可以替换为: python -c "import sys; print ''''.join(sorted(sys.stdin.readlines()))" could be replaced by: python -c" print''''。join(sorted(sys.stdin.readlines()))" 因为sys肯定是最常用的模块(它是在我的系统中导入的108个/阶段,每个模块中有188个Python 2.4 stdlib模块的b ),我希望很少有人能够使用它。会受到 命名空间冲突的影响。 其他语言(例如C#)总是使他们的系统命名空间可用 而不需要一个特殊的导入。 简而言之,鉴于sys的广泛使用,其明确的性质,以及它确实已内置的事实,虽然没有这样曝光,但我认为如果没有 导入声明,即使系统总是被允许,我们会更好。 - Michael Hoffman python -c "print ''''.join(sorted(sys.stdin.readlines()))" Since sys is surely the most commonly used module (it is imported in 108of 188 Python 2.4 stdlib modules on my system, and certainly more thanany other module), I would hope few people would be affected by anamespace collision. Other languages (e.g. C#) always make their system namespace availablewithout needing a special import. In short, given the wide use of sys, its unambiguous nature, and thefact that it really is built-in already, although not exposed as such, Ithink we would be better off if sys were always allowed even without animport statement.--Michael Hoffman Micha el Hoffman< ca ******* @ mh391.invalid>写在 新闻:df ********** @ gemini.csx.cam.ac.uk: Michael Hoffman <ca*******@mh391.invalid> wrote innews:df**********@gemini.csx.cam.ac.uk: 人们会怎么想?关于将sys添加到__builtins__以便import sys不再需要?这是我必须添加到我写的每个脚本中的东西,因为他们在底部有这个成语,所以不是单行的: 如果__name__ ==" ; __ main __": sys.exit(main(sys.argv [1:]))另外,import sys的必要性使一些单行程比它们应该更加笨拙 - 这肯定是我在单行中最缺少的模块。对于示例,有了这个提议,这个不优雅的单行: 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: 这篇关于建议:将sys添加到__builtins__的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
11-01 05:15