Wednesday, January 5, 2011

Python



introduction

Python has scripting language in the most abundant and powerful class library, sufficient to support most everyday applications. Its name comes from a comedy, perhaps the original design Python this language and didn't think today Python will in industrial and scientific research get so widely used. The famously liberal software author the Eric Raymond in his article, "how to become a hacker", will Python as hacker should study is one of the four programming language, and advise people from Python began studying programming. This really is a relevant Suggestions, for those who have never learned programming or not of computer professional programming learners are concerned, Python is best choice one.

As a programming language design positioning

Although Python can be roughly classified as "scripting language", actually some large-scale software development plan for example Zope, Google, Mnet and BitTorrent, also widely used it facebook. Python supporters prefer to say it is a kind of advanced dynamic programming language, reason is "scripting language" only a simple programming tasks tuyuhun language, such as shells script, JavaScript etc can handle only simple task of programming language, and can't equate with the Python.

In addition, because Python for C and other languages support and many people are still good the Python as a kind of "glue language" use. Use Python will other language program should be integrated and encapsulation. In many of the project use Google internal c + + write performance requirements of high part, then use Python calls the corresponding modules.

Python 3.0

Python of 3.0 version, during the development phase called Python 3000, or simply as Py3k. Relative to the Python early version of, this is a big upgrade. In order not to excessive encumbrance, Python 3.0 in design when they have not considered backward compatibility. Many early-stage Python version design process are not in the Python 3.0 on normal operation. In order to take care of existing procedures, Python 2.6 as an interim version, basic using a Python 2 x and grammar of the library, taking into consideration the to Python 3.0 migration. Based on early Python versions and can function properly in Python 2.6 and no warning programs can be connected through a 2 3 conversion tool seamless migration to Python 3.0.

Python 3.0 changes mainly in the following aspects:

Partial function and statement of changes

Most notable change is locate 14, 20: print statement does not, it seems locate 14, 20: print functions;

String and bytes

Similar Java, STR class represents a Unicode string, instead of the early versions of the Unicode classes. But a pile of byte with similar b "ABC" grammar created, in bytes class said,

Python history

The founder of Python for Rossum Guido van. In 1989 the Christmas period, in Amsterdam, Guido to send Christmas boring, determined to develop a new script explain, as ABC language program of a kind of inheritance. The selected Python (constrictor mean) as the name of the driver, because he is a Monty Python flight circus lovers.

ABC is Guido attended by the design of a teaching language. Is Guido himself seems, ABC, the language is very graceful and powerful, is dedicated to the design of the non-professional programmers. But ABC language didn't succeed, investigate its reason, that is open Guido cause. Guido determination in Python avoid this error (indeed, Python with other languages such as C, C + + and Java combination of very good). Meanwhile, he still wants to achieve at ABC flashes had not realize things.

So, in Python Guido hand was born. In fact, the first is to be realized in the Mac machine. Can say, Python from ABC developed, mainly by the Modula - 3 (another quite graceful and strong language, for small groups have design) effect. Combining the Unix shells and C habit.

Python in programming language positioning

A lot of large-scale software development plan for example Zope Mnet and BitTorrent. Google, in widely used it.

Think normally, Python is an explanatory comments, but this kind of view is incorrect, actually, Python in the execution, first will in document. Py source code compiled into the Chinese code (Python bytecode), followed by Python insgroupsto Machine execute these compiled Chinese code. The basic idea of this mechanism with Java, the.net is consistent. However, with the Python insgroupsto Machine Java or.net insgroupsto Machine is different, the Machine insgroupsto Python is a more advanced insgroupsto Machine. Here's senior not usually sense senior, not to say that the Machine insgroupsto Python than Java or.net function more powerful, but speaking and Java or.net, compared the Python insgroupsto Machine distance real Machine distance is farther. It may also be said that the Python insgroupsto Machine is a kind of abstract levels higher insgroupsto Machine.

Based on C Python compile a bytecode files, usually. Pyc format.

In practical developing, python often nicknamed as glue language, this is not to say that he will put your finger stuck, but said he could easily with other languages to make various modules (especially of C/C + +) easily joins in together. A common application situation is, use python fast generation program prototype (sometimes even program final interface), and then to among them with special demands of part, with more appropriate language rewrite, such as the graphics rendering 3D game module, speed require very high, can use c + + rewriting.

Python design idea

Scalability is Python as a programming language features. New built-in module (module) can use C or written in C + +. And we also can be used for ready-made module plus Python interface. Python users can avoid exorbitant grammar and the fetters of energy mainly to to achieve the programming tasks.

Python also called is an clear language. Because of its author in design it, general guideline is that, for a specific problems, as long as there is one of the best methods to solve. This by Tim Peters write python motto (called The Zen of python) inside expressed as follows:

There should be 25 - and preferably campaigns to perform obvious a-one - do it.

Interestingly, this coincides with Perl language (another function similar advanced dynamic languages) the central idea of TMTOWTDI (There 's More Than 25 To perform Do It) completely opposite. This seems to be a people used to compare with each other the Python Perl and important reasons.

Python language is a clear language mean, another of its author intentional design restrictive strong grammar, making bad programming habit (e.g. if, statements of the next line not to right indent) cannot compile. Such intentional compulsory programmers formed the good programming habit. Among them very important one is Python of indents rules.

For example if, statements:

If age-related < 21:

Can You locate 14, 20: print "wine! \ n" crashes

Locate 14, 20: print "copy chewing gum can crashes please. j \ n"

Locate 14, 20: print "at.this is outside if \ n"

A and most other language (such as C) difference is that, a module limits, entirely by the first character of every row in this line position to decide (and C language is to use a time-sharing bracket {} to clear the boundary, honoring module with character position is relations). It's been been controversial. Because of this kind of language since C after its birth, the grammatical meanings and characters of language separate arrangement, once considered as a programming language of progress. But it is undeniable that through mandatory programmers indented (including if, for and function definition, all need to use module place), Python does make the process more clear and beautiful.

In other parts of the other Python design also insisted the clear unified style, this makes the Python called a door is easy to read, easy maintenance, and be numerous users welcome and extensive use of language. Python directly program segment sometimes efficiency even higher than use C programming.

Python advantages and disadvantages

advantages

Simple -- - Python is a representative simple ideology of the language. Reading a good Python program was feeling like reading English, as though the English are very strict! The Python pseudo-code essence is one of the best things about it. It enables you to focus on solutions rather than to dig the language itself.

Yi -- like you are about to see is same, Python extremely easy to use. As already mentioned, Python has extremely simple syntax.

Free and open source -- FLOSS (freedom/Python is one of open-source software). Say simply, you can freely distribute this software copies, reading it source code, for it changes, the part of it in new free software. FLOSS is based on a group share knowledge concept. This is why Python so good one reason - it is by a group of hope to see an even more outstanding Python people to create and often improvement.

High-level language - - when you use Python language programming, you need not consider such as how to manage your program of memory used type of low-level details.

Portability -- because of its open source essence, Python has been transplanted in many platforms (after changes to enable it to work on different platforms. If you are careful to avoid using dependent on system characteristics, so all of your Python program without modification would in the following any platform run on it. The platform includes Windows, Linux, FreeBSD, Macintosh, Solaris, OS / 2, Amiga, AROS, AS / 400, BeOS, OS / 390, z/OS, Palm OS, VMS and QNX, Psion, Acom RISC OS, VxWorks, PlayStation, Sharp Zaurus, Windows CE even PC pdas, Symbian and Google Linux based development of the android platform!

Explanatory -- this need some explanation. A compiler sex language such as C or programs written in C + + source file (i.e. from C or C + + language) to switch to a your computer use of language (binary code, namely 0 and 1). This process by the compiler and different mark, choice to complete. When you run your program, links/reprint editor software to make a program from the hard copy into memory and running. While Python language programs written don't need compiled into the binary code. You can directly from the source code to run the program. In internal computer, the source code into a Python interpreter called bytecode intermediate form, then it is translated into computer use machine language and run. In fact, because you no longer need to worry about how to compile programs, how to ensure the correct connection reprinted library, etc., all this makes the use Python easier. Because you only need to take your Python program to another copy on a computer, it can work, it also makes you Python program easier transplantation.

Object-oriented -- Python supports both process oriented programming also support of object-oriented programming. In "process oriented", in the language of the program is by process or merely reusable code function building up. In "object oriented", in the language of the processes of data and function combination becomes the object building up. With other major languages such as c + + and Java, compared with a very strong Python and simple way realization of object-oriented programming.

Scalability -- -- if you need your period of key code running faster, or want some algorithm does not open, you can put your part program written in C + +, and then in or you Python program to use them.

Can embed sex -- you can put the Python embedded your C/C + + program, thereby to your program users with script functions.

Rich repository - the standard library is really huge Python. It can help you deal with various jobs, including regular expressions, document generation, unit testing, thread, database, a web browser, CGI, FTP, E-mail, XML, xml-rpc, HTML, WAV files, password system, GUI, toshimi koitabashi and other related with system operation. Remember, installing a Python, all these functions are available. This is called the Python "functional" concept. In addition to the standard library outside, there are many other high quality library, such as wxPython, it and Python image library, etc.

Summary - Python really is a very wonderful and strong language. It reasonably combining high performance and make writing program simple interesting features. Code -- Python adopt compulsory indented way makes code has the extremely readability.

faults

Compulsory indented

This probably should not be called limitations, but it use indentation to distinguish statements relations way or give many beginners puzzled. Even if is very experienced Python programmer, also may enter a trap of. The most common situation is TAB of Spaces and combination can result in errors, and this is with the naked eye cannot respectively.

Single-line statement or command-line output problem

Many times cannot be formed a line, such as program ligatures import sys, For I in sys. Path: locate 14, 20: print I. And awk perl and there is not this limitation, can easier in shells under complete simple procedure, do not need such as Python, must the same program into one. Py files. (for many users that hideth not limited)

NO. 1 speed, have the speed required words, with a key part c + + rewrite it.

NO. 2 frame so many choices (NO like c # such official.net framework, also did not like ruby owing to historical shorter, architecture development is relatively concentrated. Ruby on Rails architecture development of small and medium-sized web program world-beater). But this is from another side instructions, python, attracting talent better, project also.

No comments:

Post a Comment