是什么让 Python 成为一种好的脚本语言?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1659559/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What makes Python a good scripting language?
提问by Moeb
If you have to choose a scripting language, why would you choose Python?
如果必须选择一种脚本语言,为什么会选择 Python?
回答by Stefano Borini
Because it has clean and agile syntax, it's fast, well documented, well connected to C, has a lot of libraries, it's intuitive, and it's not perl.
因为它的语法干净灵活,速度快,文档齐全,与 C 连接良好,有很多库,很直观,而且不是 perl。
回答by Alex Martelli
Depends on what you mean by "scripting language". If you mean I'm going to be extensively typing it in at a shell prompt, I want the mysterious but utter conciseness of Bash or zsh; if you mean I'm going to have to embed it in 2000 apps in each of which it will typically be used for "customization" scripts of 2 or 3 lines, I probably want the minimalist simplicity of Lua (I may not like programmingin Lua all that much, but 2-3 lines is indeed "scripting" more than "programming", and the near-zero cost of embedding Lua in anything will then dominate).
取决于您所说的“脚本语言”是什么意思。如果你的意思是我要在 shell 提示符下大量输入它,我想要 Bash 或 zsh 神秘但完全简洁;如果你的意思是,我将不得不在每个应用程序2000,其中它通常被用于2条或3线“定制”脚本嵌入它,我可能想的Lua简约简单(我可能不喜欢编程的Lua 这么多,但 2-3 行确实比“编程”更“脚本化”,然后将 Lua 嵌入到任何东西中的成本接近零将占主导地位)。
Python, like Perl or Ruby, is mostly used to write MUCH more substantial "scripts" (impossible to distinguish from "programs", except maybe by total bigots;-) -- in which case, very different considerations apply wrt "real" scriptinglanguages such as bash or zsh, or lua or tcl for a different definition of "scripting language". Basically, if what you want is a dynamically (but strongly) typed language, with full capacity to scale up to very large software systems, and yet quite good at "playing with others"... then you surely have a particularlyweird definition of "scripting", my friend!-) But that's the arena where Python, Ruby and Perl mostly play -- and where one could debate one against the other (but any one of them would crush any other popular language I know -- yeah, I've known and loved and used rexx, scheme, Smalltalk, and many many others, but none could hold a candle to the Big Three I just mentioned in thisarena!-).
Python,如 Perl 或 Ruby,主要用于编写更多实质性的“脚本”(无法与“程序”区分开来,除非可能是完全偏执的人;-)——在这种情况下,非常不同的考虑适用于“真实”脚本bash 或 zsh 或 lua 或 tcl 等语言,用于“脚本语言”的不同定义。基本上,如果您想要的是一种动态(但强)类型的语言,具有扩展到非常大的软件系统的全部能力,并且非常擅长“与他人一起玩”……那么您肯定有一个特别的“脚本”的奇怪定义,我的朋友!-) 但那是 Python、Ruby 和 Perl 主要使用的领域——并且可以相互辩论(但它们中的任何一种都会粉碎我所知道的任何其他流行语言—— - 是的,我知道、喜欢和使用过 rexx、scheme、Smalltalk 和许多其他人,但没有人能与我刚才在这个领域提到的三巨头相提并论!-)。
But unless you clarify your terminology, "scripting language" remains an empty, meaning-free sound, and any debate surrounding it utterly useless and void of significance.
但是除非你澄清你的术语,否则“脚本语言”仍然是一种空洞的、没有意义的声音,围绕它的任何争论都毫无意义且毫无意义。
回答by J S
I think it depends on your definition of scripting language. There are (at least) two camps. One is that scripting language should be embeddable, so the core should be small (like Lua or Tcl). The second camp is scripting for system administration, and Perl is definitely in this camp.
我认为这取决于您对脚本语言的定义。有(至少)两个阵营。一是脚本语言应该是可嵌入的,所以内核应该很小(如 Lua 或 Tcl)。第二个阵营是用于系统管理的脚本,而 Perl 绝对属于这个阵营。
Python is a general programming language, not particularly in either camp (but also not unsuitable), probably most useful for writing small or medium sized programs.
Python 是一种通用的编程语言,在任何一个阵营中都不特别(但也并非不适合),可能对编写小型或中型程序最有用。
回答by monksy
I haven't programmed in python before but my guess would be the libraries available and the size of the userbase.
我之前没有用 python 编程过,但我猜可能是可用的库和用户群的大小。
回答by inspectorG4dget
It's very intuitive, has a ton of libraries, helps you whip up a script VERY FAST. You can use it for small projects or big projects and can compile into an EXE for windows, an APP for mac or into a cross platform application.
它非常直观,拥有大量库,可帮助您非常快速地编写脚本。您可以将它用于小项目或大项目,并且可以编译成windows的EXE、mac的APP或跨平台的应用程序。
I has possibly the cleanest syntax of any language I have seen to date and can do everything from adding numbers to system calls to reading various different types of files. Hell, you can even do web programming with it.
我可能拥有迄今为止我见过的任何语言中最简洁的语法,并且可以完成从添加数字到系统调用到读取各种不同类型文件的所有操作。地狱,你甚至可以用它进行网络编程。
I see no reason why I would advise against python... ever.
我看不出为什么我会建议不要使用 python ......永远。
回答by farincz
read http://python.net/~goodger/projects/pycon/2007/idiomatic/handout.html
阅读http://python.net/~goodger/projects/pycon/2007/idiomatic/handout.html
it this short article you can see many power features and elegance. Especially things like defaultdict makes your code much more shorter, readable and maintainable.
在这篇简短的文章中,您可以看到许多强大的功能和优雅。尤其是像 defaultdict 这样的东西会让你的代码更短、更易读和更易于维护。
回答by Xinus
because it helps you in RAD, its the best language for writing opensource software
因为它可以帮助您使用 RAD,它是编写开源软件的最佳语言
Take a look at this link http://www.python.org/about/
回答by Xinus
I would try a number of "scripting" languages (as well as some languages with good static type inference), and then select the language(s) that best fit the problem.
我会尝试许多“脚本”语言(以及一些具有良好静态类型推断的语言),然后选择最适合问题的语言。
This may be for a number of reasons including, but not limited to: Runtime targets and performance (as dictated by functional requirements), library support (don't re-invent the wheel allthe time), existing tool support, existing integration support (if X supports Y, is it real feasible to get X to support Z just to use Z?), and most important to a subjective question: personal choice and zealot fanaticism :)
这可能是出于多种原因,包括但不限于:运行时的目标和绩效(如规定由功能性需求),库支持(不重新发明轮子所有的时间),现有的工具支持,现有的集成支持(如果 X 支持 Y,那么让 X 支持 Z 只是为了使用 Z 真的可行吗?),最重要的是一个主观问题:个人选择和狂热的狂热:)
The term "scripting language" is absolutely horrid-- unless perhaps you really DOmean SH or MIRC "script". The phrase "dynamically typed language" is a much better qualifier.
术语“脚本语言”,绝对可怕的-除非也许你真的DO平均SH或MIRC“脚本”。短语“动态类型语言”是一个更好的限定词。