001.python Preface
*This series of articles is my personal study 《python Learning manual ( The fifth edition )》 Learning notes of , Most of them are the summary and personal understanding of the book , A small part of the content is the extension of relevant knowledge points .
For non-commercial use, please indicate the author and source ; Please contact me for commercial use ([email protected]) Get permission .
*
About python Analysis of advantages and disadvantages
-
python High readability , Transplantation is good -
The code is concise , Complete the same problem compared to java and C++, The amount of code is its 1/5~1/3 -
Efficiency is relative C Language is called poor , But it's not that bad -
Open source , The community is very active , There are a lot of libraries that can be used directly by the government and the people
*Here comes a question , About the advantages and disadvantages of open source . The following is personal understanding , Just for my personal opinion , Not authoritative
The advantages of open source
1) Open source , Relatively safe ;
2) Most open source software is free to use , Even if you need a paid license , The licensing fee is relatively low .
3) Open source software communities are generally more active , Software update iterations are fast .
About the shortcomings of open source software
1) Open source software is generally maintained by the community , The speed of iteration depends on the activity of the community . And it is possible that the software will stop maintenance due to the transfer of interest of developers or other factors , There is a certain risk
2) The use threshold of open source software is relatively high , Although the development cost is saved , But for deployment and maintenance personnel , A certain technical ability is required . such as , If you use commercial software , Later support can be done by the software provider , And open source software does not have a department responsible for responding , So the deployment and maintenance are all done by our own technicians . That's why open source software licenses are cheap and even free , Why many companies still choose commercial software . After all, the problem that can be solved with money , It's not a problem for the rich .
3) Open source software lacks dominant control , Open source community is a community with relatively high degree of freedom . Lack of absolute dominance . This is because the open source community is too active , This leads to the confusion of the version Branch .
*
python Operation process
python It's an explanatory language . That's right , But not exactly .
First of all, explain briefly the interpretive language and the compiler language :
-
「 Compiler language :「 Source code is 」 compiler 」 After a series of processing, the final product is strongly related to the processor instruction set , Binary files that can be executed directly by the processor . -
Typical C Language and C++. In common use GCC Compiler for example , Executable binaries programmed from code are precompiled -> compile -> assembly -> Links and so on . -
advantage : Compiled languages from source code to executable binaries are done before they run . So you don't need to process the source code again during execution , More efficient -
shortcoming : alike , Because the source code has been processed into a processor strong binary before execution , So the portability is poor .
-
-
「 Explanatory language :「 Source code from 」 Interpreter 」 stay 「 Runtime 」 Translate sentence by sentence into machine code . -
java,python And other languages belong to this category . But not strictly belong to this category . Because the so-called interpretive languages now have so-called optimization , The actual interpreter is not translating the source code , It's pretreated “ Partially Prepared Products ” -
advantage : Translation is performed by the interpreter , Platforms are not relevant , Good portability . -
shortcoming : -
Low efficiency -
Because there is an interpreter between the platform and the source code , So when deploying , You need to install the relevant operating environment, such as java Of jre etc. . Of course, it can also be packaged into corresponding binary files , image py2exe Such a tool , But it will also python Interpreter and source code ( Bytecode ) It's just packed at the same time .
-
-
「python Operation process 」
-
Source code (.py) It is first processed into bytecode by the interpreter (.pyc) -
Program runtime , Bytecode (.pyc) Interpreted by the interpreter as executable instructions
We will not talk about program execution for the time being , In the subsequent “ Lifetime series ” There may be related articles about this .
Here's a brief answer to bytecode .pyc File generation . First , Bytecode is platform independent , A low form of expression , It is mainly used to improve the running speed .
If python The interpreter has write permission , stay python3.2 Before , Bytecode files will be saved in a subdirectory under the source code directory __pycache__
in , And the interpreter version information will be saved in the corresponding .pyc In the file . stay python3.2 after , Bytecode files will still be saved in this directory , But the version information is saved in the file name , As shown in the figure below :
If python Interpreter does not have write permission , Bytecode files are also generated , But the file is saved in memory .
「 When to recompile 」
If the source code has not been modified , When the code is executed again ,python The interpreter will directly interpret the corresponding bytecode file without having to redo it " compile "( Be careful , The compiler is quoted .) Bytecode . So when to start again " compile " What about bytecode ? Two cases :
-
「 Source file changes :」 python The interpreter checks the last modified timestamp of the source and bytecode files , If the time is inconsistent , Then re " compile " Bytecode -
「 Interpreter version changes :」 If the version of the interpreter used by bytecode file does not match the version of the interpreter used by the currently executing code , Then re " compile "
python Interpreter
python There are many implementations of the interpreter for , Here are some famous ones . Just get to know it , After all, most of them are standard ones CPython.
-
「CPython:」 from ANSI C Language implementation , It's standard Python Interpreter . -
We are python Downloaded from the official website python What is used in the suite is CPython -
The fastest , Most complete , newest , The most robust
-
-
「Jython:」 The purpose of this thing is to Python and Java Integrate , take Python Source code translated into Java In order to make it run in JVM On . -
「IronPython:」 and Jython almost , But this guy's purpose is to make python Running on the .net Under the framework . -
「Stackless:」 CPython Optimization for concurrency , The concept of coprocess is introduced -
「PyPy:」 use JIT(just in time) technology , It is said that it can be compared with python even to the extent that C Language is faster , In algorithm intensive and computing intensive scenarios, the performance is more outstanding .( I don't understand this , I dare not talk nonsense )
This article USES the mdnice Typesetting