Exploring the mysteries of the Python language

Source: Internet
Author: User

I have many things to say about the mysteries of the Python language. First of all, I personally think that the Python language is an object-oriented, literal translation computer programming language, and also a powerful and complete general-purpose language, it is also a very useful language for beginners.

The first reason I gave up PHP is the language. PHP is actually not a language, but a huge plug-in structure that shows low-level libraries in a high-level form. Most developers use the C function (curl, mysql, gd, etc.) Packaging language. In general, their libraries are very simple to display. As a result, PHP APIs are inconsistent.

The second problem with PHP is the management of Python. The PHP language is actually designed by the committee, and no one has come up with any consensus standards. PEAR has its own standards and PHP has its own standards, which makes SPL classes more Java-style, but PEAR is quite different.

Over the past 11 years of development in PHP, I have known many expert developers in the PHP field. They also have many opinions on PHP. In addition to the Committee issues and standard chaos issues mentioned above. Due to the wide application scope of PHP, backward incompatibility causes great damage to the code. It is also mentioned that PHP lacks many features of modern languages. Now let's talk about Python:

The creation method of Python is almost the opposite of that of PHP. First, Python is led by Benevolent Dictator and Guido van rosum. The language development is led by a single person. Therefore, its development, management, and long-term operations will maintain good continuity.

Core developers of Guido and Python use PEP to create standards and use public interfaces to demonstrate how standards are created. In addition, Guido's language features are not good enough. It does not appear in the language layer if there is no ++ operator, and the comparison operator is not allocated ). The continuity feature extends to the entire Python community, so it is hard to find that Python in different projects is completely different.

One feature of my favorite Python is its clarity. When opening a file in Python, I will clearly know what the code looks like, and think that I have been overwhelmed by PHP many times, I think this feature is very useful.

  • How to build a Python development environment correctly
  • Notes for getting started with the Python Module
  • Graphical Python interpreter configuration problems
  • Detailed introduction and analysis of Python build tools
  • Deep description of Python source file nature

In short, Python has very good system-level features. Another great feature of Python is straightforward. Need namespace (namespace )? The file name is The namespace. Do you need a module? You only need to replace it with a _ init _. py file. Do you need to rename the function? Only new_func = old_func is required.

Create a Thread instance and input a function t = threading. Thread (target = _ func_name, args = (parameter tuples) in the constructor to create a Thread instance. Input an callable class object in the constructor to define a class ThreadFunc. The call _ function must be rewritten in the class for the Thread to call t = threading. Thread (target = ThreadFunc instance)

A subclass is derived from Thread. The instance class MyThread (threading. Thread) of the subclass is created to overwrite the run function in threading. Thread for Thread execution. After all the above threads are created, they are started using the start () method of the thread instance, and the join () method is used to add a spin lock. How can we ensure that all important threads have ended when multiple threads run the spin lock? In the threading module.

Each Python language has a join function, which is actually an infinite loop (also called a spin lock) waiting for the release of this thread lock ). When a thread instance is started, explicitly calling join () will force the main thread to wait for the thread's spin lock to be released. This situation is common in task flow programs of sequential processes.

Here, I think we may wish to build a general module to implement thread synchronization for any process. For example, in a download process, you only need to input a URL. The main thread does not have to wait until the download is complete before executing other tasks. For such a special process function, we can use the function modification function.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.