Python Import Module source code processing logic denoted __python

Source: Internet
Author: User

The total entrance is load_module.

The imported file has a py file, go load_source_module

1. Get the latest time of the py file

2. Try to open PYc, open failed, then recompile, open successfully, from the PYc Inside Out magic and timestamp, there is a different, recompile pyc. If all the same, the code snippet is read from PYC.

3. PYc Open or magic, timestamp proof fails, recompile PYC.

3.1 On the py file for AST parsing, return to Pycodeobject, first open PYc, in the open file description through Fdopen converted to file operation pointer, then write magic, timestamp, code.

4. Executing code

4.1 Code is from code read from PYC

The 4.2 code comes from the code after the AST return to the PY

The imported module does not have a py, only the PYc file. Go Load_compiled_module

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.