know python

1. Python development background

  • The author of Python, Guido von Rossum (Guido van Rossum, Chinese Python programmers call him Uncle Turtle), Dutch. In 1982, Uncle Turtle received a master's degree in mathematics and computing from the University of Amsterdam. However, although he is a mathematician, he enjoys computers even more. In his words, although he has both mathematics and computer qualifications, he always tends to do computer-related work and is passionate about doing anything related to programming.

  • At that time, Uncle Turtle came into contact with and used languages ​​such as Pascal, C, Fortran and so on. The basic design principle of these languages ​​is to make machines run faster. In the 1980s, while IBM and Apple had made the PC wave, these PCs were low-profile. For example, in the early Macintosh, only 8MHz CPU frequency and 128KB RAM, a large array can fill the memory. The core of all compilers is to do optimizations so that programs can run. To increase efficiency, languages ​​also force programmers to think like computers so that they can write programs that are more machine-like. In those days, programmers could not wait to squeeze every inch of the computer's power with their hands. Some people even think that C pointers are a waste of memory. As for dynamic typing, automatic memory management, object orientation... don't even think about it, it'll crash your computer.

  • This way of programming troubles Uncle Turtle. Uncle Turtle knows how to write a function in C language, but the whole writing process takes a lot of time, even if he already knows exactly how to implement it. His other option is the shell. The Bourne Shell has been around for a long time as an interpreter for UNIX systems. UNIX administrators often use the shell to write some simple scripts to perform some system maintenance work, such as regular backups, file system management, and so on. The shell can act like glue, linking together many functions under UNIX. Many programs with hundreds of lines in C language can be completed in just a few lines under the shell. However, the nature of the shell is to invoke commands. It's not really a language. For example, the shell does not have a numeric data type, and addition operations are complicated. In short, the shell cannot fully mobilize the functions of the computer.

  • Uncle Turtle hopes to have a language that can fully call the functional interface of the computer like the C language, and can be easily programmed like the shell. ABC language makes Uncle Turtle see hope. ABC was developed by the Institute of Mathematics and Computing in the Netherlands. Uncle Turtle works at the institute and is involved in the development of the ABC language . ABC languages ​​are for teaching purposes. Unlike most languages ​​of the time, the goal of the ABC language was to "make the user feel better". ABC language hopes to make the language easy to read, easy to use, easy to remember, easy to learn, and to stimulate people's interest in learning programming. For example, here is an ABC program from Wikipedia that counts the total number of words that appear in a text:

   HOW TO RETURN words document:
    PUT {} IN collection
    FOR line IN document:
        FOR word IN split line:
          IF word not.in collection:
              INSERT word IN collection
    RETURN collection
  • HOW TO is used to define a function. A Python programmer should easily understand this program. The ABC language uses colons and indentation to denote program blocks. There is no semicolon at the end of the line. There are also no parentheses () in for and if constructs. Assignment uses PUT instead of the more common equals sign. These changes make the ABC program read like a piece of text.

  • Despite its good readability and ease of use, the ABC language did not eventually catch on. At the time, the ABC language compiler required a relatively high-end computer to run. And the users of these computers are usually computer savvy, and they think more about the efficiency of the program than how hard it is to learn. In addition to the hardware difficulties, the design of the ABC language also has some fatal problems:

    • Poor scalability. ABC language is not a modular language. If you want to add functionality to the ABC language, such as support for graphics, you have to change a lot.

    • IO cannot be performed directly. The ABC language cannot directly manipulate the file system. Although you can import data via something like a text stream, ABC cannot read and write files directly. Input and output difficulties are fatal to computer languages. Can you imagine a sports car that can't open the door?

    • Overly innovative. ABC uses natural language to express the meaning of the program, such as HOW TO in the above program. However, for programmers, they are more accustomed to using function or define to define a function. Likewise, programmers are more accustomed to assigning variables with the equals sign. Although the ABC language is special, it is also very difficult to learn.

    • Difficulty spreading . The ABC compiler was large and had to be kept on tape. When Uncle Turtle was visiting, he had to have a big tape to install the ABC compiler for others. In this way, it is difficult for the ABC language to spread quickly.

  • In 1989, in order to pass the Christmas holidays, Uncle Turtle began to write a compiler for the Python language. The name Python comes from the TV series Monty Python's Flying Circus, which is loved by Uncle Turtle. He hoped that the new language, called Python, would meet his vision: to create a full-featured, easy-to-learn, and extensible language between C and the shell. As a language design enthusiast, Uncle Turtle has already tried to design languages. This time, it was just a pure hacking act.

2. The birth of the Python language

  • In 1991, the first Python compiler was born. It is implemented in C language and can call C language library files. From birth, Python has had: classes, functions, exception handling, core data types including tables and dictionaries, and a module-based extension system.

  • A lot of Python syntax comes from C, but is strongly influenced by the ABC language. Some provisions from the ABC language are controversial to this day, such as mandatory indentation. But these syntax rules make Python easy to read. On the other hand, Python wisely chooses to obey some conventions, especially those of the C language, such as return-equals assignment. Uncle Turtle believes that if there is something established in "common sense", there is no need to be overly entangled.

  • Python has been especially concerned with extensibility from the very beginning. Python can be extended at multiple levels. From a high level, you can import .py files directly. Under the hood, you can reference C libraries. Python programmers can quickly use Python to write .py files as extension modules. But when performance is an important factor to consider, Python programmers can go to the bottom, write C programs, compile them into .so files and import them into Python for use. Python is like building a house out of steel, first define a big frame. And programmers can expand or change quite freely under this framework.

  • The original Python was developed entirely by Uncle Turtle himself. Python is welcomed by Uncle Turtle's colleagues. They are quick to use feedback and participate in Python improvements. Uncle Turtle and some colleagues form the core team of Python. They spend most of their spare time hacking Python. Subsequently, Python expanded beyond the Institute. Python hides many machine-level details and hands them over to the compiler, and highlights the programming thinking at the logical level. Python programmers can spend more time thinking about the logic of the program than the specific implementation details. This feature attracts a large number of programmers. Python became popular.

  • Computer hardware is getting more and more powerful and Python is easy to use, so many people are turning to Python. Uncle Turtle maintains a mail list, and Python users communicate via email. Python users come from many fields, have different backgrounds, and have different needs for Python. Python is quite open and easy to expand, so when users are not satisfied with the existing functions, it is easy to expand or transform Python. These users then send the changes to Uncle Turtle, who decides whether to add new features to Python or the standard library. It would be a great honor if the code could be incorporated into Python itself or the standard library. Due to his supreme decision-making power, Uncle Turtle was called "the benevolent dictator for life".

  • Python and its standard library are powerful. These are contributions from the entire community. Python developers come from different fields, and they bring the advantages of different fields to Python. For example, regular expressions in the Python standard library refer to Perl, while functions such as lambda, map, filter, and reduce refer to Lisp. Some features of Python itself and most of the standard library come from the community. The Python community continues to expand and has its own newsgroup, website, and foundation. Since Python 2.0, Python has also changed from a mail list development method to a completely open source development method. A community atmosphere has been formed, the work is shared by the entire community, and Python has developed more rapidly.

  • To this day, the framework of Python has been established. The Python language organizes code with objects as the core, supports multiple programming paradigms, adopts dynamic typing, and automatically performs memory recovery. Python supports interpreted operation and can call C library for expansion. Python has a powerful standard library. Since the standard library system has stabilized, the Python ecosystem has begun to expand to third-party packages. These packages, such as Django, web.py, wxpython, numpy, matplotlib, PIL, upgrade Python to a species-rich rainforest.

  • Python advocates beauty, clarity, and simplicity, and is an excellent and widely used language. Python ranks eighth in the TIOBE rankings. It is the third largest development language of Google, the basic language of Dropbox, and the server language of Douban. The development history of Python can serve as a representative and give me a lot of inspiration.

  • The community has played an important role in the development of Python. Uncle Turtle believes that he is not an all-round programmer, so he is only responsible for formulating the framework. If the problem is too complicated, he will choose to go around, that is, cut the corner. These issues are eventually resolved by others in the community. The talent in the community is extremely rich, and there are people who are happy to deal with things that are a little far from development, such as creating a website and raising funds. Today's project development is more complex and larger, and cooperation and an open mind are the keys to the ultimate success of the project.

  • Python has learned a lot from other languages, whether it's ABC, which has entered history, or C and Perl, which are still in use, and many other languages ​​that are not listed. It can be said that the success of Python represents the success of all the languages ​​it borrows from. Likewise, Ruby borrows from Python, and its success represents the success of some aspects of Python. Every language is a hybrid, it has its good points, but also all kinds of flaws. At the same time, the judgment of a language's "good or bad" is often subject to external factors such as platform, hardware, and era. Programmers go through many language battles. In fact, if you accept various languages ​​with an open mind, maybe one day, programmers can mix their own languages ​​like Uncle Turtle.

    3. Common sense of key points

  • Pronunciation and Spelling of Python

  • The author of Python is Guido van Rossum (Uncle Turtle)

  • Python was officially born in 1991

  • The Python interpreter is now implemented in multiple languages. We commonly use CPython (the official version of the C language implementation), and others include Jython (which can run on the Java platform), IronPython (which can run on the .NET and Mono platforms), and PyPy. (implemented in Python, supports JIT just-in-time compilation)

  • Python currently has two versions, Python2 and Python3, the latest versions are 2.7.13 and 3.6.2 respectively

  • Life is shot, you need Python. Life is short, I use Python.

4. The advantages and disadvantages of Python

advantage

  • Simplicity : Python is a language that represents the idea of ​​simplicity. Reading a good Python program feels like reading English, albeit very strict! This pseudocode nature of Python is one of its greatest strengths. It enables you to focus on solving problems rather than figuring out the language itself.

  • Easy to learn: As you will see, Python is extremely easy to learn. As mentioned earlier, Python has an extremely simple syntax.

  • Free, Open Source : Python is one of FLOSS (Free/Open Source Software). Simply put, you are free to distribute copies of this software, read its source code, make changes to it, and use parts of it in new free software. FLOSS is based on the concept of a community sharing knowledge. This is one of the reasons why Python is so good - it was created and often improved by a group of people who wanted to see a better Python.

  • High-level language : When you write programs in Python, you don't need to think about low-level details like how to manage the memory your program uses.

  • Portability : Due to its open source nature, Python has been ported to many platforms (modified to work on different platforms). If you are careful to avoid using system-dependent features, all of your Python programs will run on any of the platforms described below without modification. These platforms include Linux, Windows, FreeBSD, Macintosh, Solaris, OS/2, Amiga, AROS, AS/400, BeOS, OS/390, z/OS, Palm OS, QNX, VMS, Psion, Acom RISC OS, VxWorks, PlayStation, Sharp Zaurus, Windows CE and even PocketPC, Symbian and Google's linux-based Android platform!

  • Interpreted language : A program written in a compiled language such as C or C++ can be converted from a source file (i.e. C or C++ language) to a language your computer uses (binary code, i.e. 0s and 1s). This process is done through the compiler and different flags, options. When you run your program, the linker/loader software copies your program from hard disk to memory and runs it. Programs written in the Python language do not need to be compiled into binary code. You can run the program directly from the source code. Inside the computer, the Python interpreter converts the source code into an intermediate form called bytecode, which is then translated into the machine language used by the computer and run. In fact, all of this makes using Python much easier since you no longer have to worry about how to compile your program, how to make sure you link with the correct libraries, etc. Since you only need to copy your Python program to another computer and it will work, it also makes your Python program more portable.

  • Object-Oriented : Python supports both procedural and object-oriented programming. In "procedurally oriented" languages, programs are built from procedures or functions that are just reusable code. In "object-oriented" languages, programs are built from objects that combine data and functionality. Compared to other major languages ​​such as C++ and Java, Python implements object-oriented programming in a very powerful and simple way.

  • Extensibility : If you need a critical piece of your code to run faster or want some algorithms to be private, you can write parts of your program in C or C++ and use them in your Python program.

  • Rich library : The Python standard library is really huge. It helps you with all kinds of jobs including regular expressions, documentation generation, unit testing, threading, databases, web browsers, CGI, FTP, email, XML, XML-RPC, HTML, WAV files, cryptography, GUIs (Graphical User Interface), Tk and other system related operations. Remember, all of these features are available as long as Python is installed. This is called Python's "full-featured" philosophy. In addition to the standard library, there are many other high-quality libraries such as wxPython, Twisted, and the Python Image Library to name a few.

  • Canonical code : Python uses mandatory indentation to make code extremely readable.

shortcoming

The Python language is very complete and has no obvious shortcomings and shortcomings. The only disadvantage is the slow execution efficiency, which is common to interpreted languages. At the same time, this shortcoming will be compensated by the increasingly powerful performance of the computer.

5. Python application scenarios

  • Web automation

    The unittest unit testing framework is not only suitable for unit testing, but also for the development and execution of web automated test cases. The test framework can organize and execute test cases, and provides a wealth of assertion methods to determine whether the test cases pass, and finally generate test results. .

  • Mobile automation

    The MonkeyRunner tool is written using Jython (Python implemented in the Java programming language). It provides multiple APIs. Through the Monkeyrunner API, a Python program can be written to simulate the operation and control of the Android device app, test its stability and take screenshots. Easily record problems that arise.

  • Web application development

    Python is often used for web development. For example, through the mod_wsgi module, Apache can run Web programs written in Python. Python defines the WSGI standard application interface to coordinate the communication between the Http server and the Python-based Web program. Some web frameworks, such as Django, TurboGears, web2py, Zope, etc., allow programmers to easily develop and manage complex web programs.

  • Automated scripts for operating system management and server operation and maintenance

    Python is a standard system component on many operating systems. Most Linux distributions, as well as NetBSD, OpenBSD, and Mac OS X, have Python integrated to run Python directly from the terminal. There are some Linux distributions with installers written in Python, such as Ubuntu's Ubiquity installer, Red Hat Linux and Fedora's Anaconda installer. Gentoo Linux uses Python to write its Portage package management system. The Python standard library contains several libraries that call operating system functions. Through pywin32, a third-party package, Python can access Windows COM services and other Windows APIs. Using IronPython, Python programs can directly call the .Net Framework. Generally speaking, system management scripts written in Python are superior to ordinary shell scripts in terms of readability, performance, code reuse, and scalability.

  • Web Crawler

    Python has a large number of HTTP request processing libraries and HTML parsing libraries, as well as mature and efficient crawler framework Scrapy and distributed solution scrapy-redis, which are widely used in crawler applications.

  • Scientific Computing

    NumPy, SciPy, Pandas, Matplotlib allow Python programmers to write scientific computing programs.

  • desktop software

    PyQt, PySide, wxPython, and PyGTK are tools for rapid development of desktop applications in Python.

  • Server software (network software)

    Python has perfect support for various network protocols, so it is often used to write server software and web crawlers. The third-party library Twisted supports asynchronous network programming and most standard network protocols (including client and server), and provides a variety of tools, which are widely used to write high-performance server software.

  • game

    Many games use C++ to write high-performance modules such as graphics display, and use Python or Lua to write game logic and servers. Compared with Python, Lua has simpler functions and smaller size; while Python supports more features and data types.

  • Idea realization, early product prototyping and iterations

    Google, NASA, Facebook all use Python heavily internally.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325257385&siteId=291194637