Right Python , Shell some thinking of
Recently learned to write Python code, read the relevant book "A Byte of Python", "python core programming", hands-on doing some shell and python exercises, and some simple view:
For the two-time scripting coding exercise, I felt that it would be a hassle to use Python to write a script to handle everyday things, because I could use the shell to use awk more skillfully in less time, These commonly used commands for SED and grep are within a very short script, completing the functionality that a large piece of code in Python can accomplish.
Two days ago, I read an article called "Web architecture-another use of Python's website", URL: http://www.fovweb.com/web/youpai-python.html. It says: The server-side development language of the web is mainly PHP and Python, where PHP is used to write Web logic, while Python is primarily used to develop internal services and background tasks. In general, the development language of the Web site architecture can be described in the following illustration:
Baidu Encyclopedia on the introduction of Python is: An object-oriented, literal translation of the programming language, but also a powerful and perfect universal language, has more than 10 years of development history, mature and stable. This language has very clear grammatical features that are suitable for various high-level tasks and can be run in almost all operating systems. At present, the relevant technologies based on this language are developing rapidly, the number of users is rapidly expanding, and the related resources are very large.
Integrated networks and books for all the evaluations of Python, Python apps are a very broad and very promising language in the future. But this does not mean that Python is suitable for any occasion, such as for an SA (System analyst), the usual management system with shell script is certainly the simplest, if pure system management, should be very few problems shell can not solve, Using a shell can also be more convenient and efficient, for example: Find all the lines that start with #, and use the shell only to have a grep command, and for Python you need open (file). ReadLines (), and then you need to read the regular expression module, Reading the text one line at a time, then analyzing whether the row satisfies the condition, requires a lot of logical code to complete the function of a shell command.
Of course, any language must have its scope, although in terms of development efficiency python is lower than the shell than the shell, but the advantages of Python relative to the shell, according to my recent learning, feeling can be summed up as follows:
(1) Python does not need to remember too many commands, the syntax is simple, the C-based people learn very easy to use, easily used. The shell has too many commands to learn, but the usual commands are not too much.
(2) Python portability is good, its standard is unified, will not appear because the platform of different operating results, but the shell command on each platform is somewhat different.
(3) Python is more powerful, the shell is a command language, but also can be seen as a command interpreter, used to receive commands such as awk, SED, etc. to complete the relevant functions. While Python is a programming language, Python provides programmers with greater freedom and flexibility to complete the coding tasks that the shell cannot or cannot accomplish, such as implementing object-oriented modular design, manipulating server databases, and so on.
(4) Python supports object-oriented, scalable, and embeddable, while providing a rich library
(5) Performance: It is clear that Python is more efficient than the shell, and there is a good reason for this is that there is a considerable overhead involved in the various interprocess IPC communications between the shell itself. The Python bottom layer is implemented in C, and its performance can be close to C, but the amount of Python code with the same functionality is many times shorter than C. So, sort by performance: C > Python > Shell, sorted by development efficiency: Shell > Python > C.
In fact, for the development of a variety of programming languages, if the pure language of the implementation efficiency, the fastest affirmation is compiled, why there will be a compilation of C. And with C, there will be Perl and Python. This should be a lot of talented programming language designers, from the beginning have been constantly pursuing, trying to language performance and ease of use to find a balance point. The language itself is only a tool, and this tool is not easy to use, in addition to much depends on the design of the language itself, on the other hand, the language user's own proficiency, ability and level are closely related.
The meaning of the birth of programming language is to solve the problem, verification idea, belong to the practice process of problem solving, such as research data mining, the main concern is the data distribution, probability model and other mathematical algorithm problem, in which language to verify the feasibility of the scheme is not very important, for the language itself the only requirement may be to use , it is best not to have too many complicated grammar, through simple learning can get started and can easily write the program, the second is to perform the efficiency is acceptable, do not need the fastest, but also can not be too slow.
In execution efficiency and ease of use, scripting language gives users a good balance, which is precisely the most important meaning of scripting language. We can write code quickly and easily by scripting, and even in some cases, this scripting code executes as efficiently as C.
Chinese New Year, visit relatives and friends is common, there is no experiment to verify the comparison of Shell, Python and C performance differences. But I found a very interesting website: http://shootout.alioth.debian.org/
This site contrasts the performance of all major languages, including time, memory, code, as shown in the following figure: in the case of running multiple representative test cases, Python's performance divided by the performance of the C language data graph, you can see that C in [Time, memory] cost less than Python, But Python is less than c on [code].