In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces the relevant knowledge of "how to understand the Python module". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
To improve the startup time of Mini Program that calls many standard Python modules, it is important to consider that if there is a file called "spam.pyc" in the directory where "spam.py" is found, it contains a so-called "byte compiled" version of the module spam.
The modification time of "spam.py" used to generate "spam.pyc" is recorded in "spam.pyc". If the recorded modification time does not match the time of the current file, the compiled file is ignored. Generally, you do not need to generate your own compiled files such as "spam.pyc". Whenever "spam.py" is compiled successfully, the interpreter tries to write the compiled version "spam.pyc", and it will not make an error if it is not writable.
If for some reason the file is not finished, the generated "spam.pyc" is recognized as incomplete and ignored. The format of the compiled file "spam.pyc" is independent of the platform, so machines with different structures can share the Python module directory.
Here are some tips for experts:
If the Python interpreter is started with the-O flag, optimized compiled code is generated and saved in the ".pyo" file. At present, there are not many optimizations, just get rid of assert statements and SET_LINENO instructions. When the-O flag is used, all bytecodes are optimized, ".pyc" files are ignored, and ".py" files are compiled into optimized bytecodes. The optimized code generated by the two optimization flags (- OO) to the Python interpreter can sometimes cause the program to run improperly.
Currently, double optimization only removes the _ _ doc__ string from the bytecode, making the ".pyo" file smaller. Some programs may rely on document strings, so such optimizations can be used only if you are sure there will be no problem. Programs read from ".pyc" or ".pyo" do not run faster than those read from ".py", they just call in faster. If a program is run by specifying the script file name on the command line.
The bytecode of the script is not written to the ".pyc" or ".pyo" file. So if you move the main code of the program into a module, only the bootstrap that imports that module in the script can slightly shorten the startup time of the script. You can have a file called "spam.pyc" ("spam.pyo" when the-O flag is used) without a corresponding source file "spam.py". This can be used to distribute a Python code base that is difficult to decompile.
The module compileall can compile all modules in a directory into ".pyc" files (".pyo" files when the-O option is specified).
Some modules are compiled directly into the interpreter, which are not the core of the language, but are programmed into the interpreter for the sake of running efficiency or to provide low-level functions such as system calls. Providing those modules is a compile-time choice.
Python module namespaces can be organized with "packages" in Python, and module names can be referenced with "dotted module names." for example, the module name A.B represents the sub-module named "B" in the package "A". Just as using modules allows authors of different modules to not have to worry about conflicts with each other's global variable names, using dotted module names allows authors of multiple module packages such as NumPy and PIL to not have to worry about conflicting module names.
For example, the Python module is available only on systems that provide amoeba underlying instructions. There is one module that deserves special attention: the sys module, which is compiled into every Python interpreter. The variables sys.ps1 and sys.ps2 define the initial prompt and line continuation prompt at interactive runtime.
These two variables are defined only when the interpreter runs interactively. The variable sys.path is a list of strings that determines the module search path for the interpreter. It is initialized to the default path specified by the environment variable PYTHONPATH, and when the environment variable is not defined, it is initialized to the default path at installation. You can modify this search path with standard list operations, such as:
> > import fibo, sys > dir (fibo) ['_ name__', 'fib',' fib2'] > dir (sys) ['_ _ name__', 'argv',' builtin_module_names', 'copyright',' exit', 'maxint',' modules', 'path',' ps1', 'ps2',' setprofile', 'settrace',' stderr', 'stdin',' stdout' Version'] this is the end of the content of "how to understand the Python module". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.