Python byte-code import uses

Source: Internet
Author: User

1. The Python module file can be compiled into bytecode form:

Name: model.py

123 def funt ():    Import model    print (model.x)    "zhangnan"    Print (x)

Top-level file, main file test.py

Import Sysimport Model  for inch sys.modules: Print (    x) print("-"*) print (Sys.modules.keys ( ))

2. Compile the file after compiling:

Model.cpython-37.pyc

Test.cpython-37.pyc

3. Directly run the Python-interpreted bytecode file

Modify the interpreted bytecode of the model module and rename it to model.py Note that the position is not changed. Because if you change the directory location of the module files, the calls to this module may fail with other modules.

The last obtained:

Mode. PYc Test. Py

Then, run the Python test.py directly to execute.

This reads the binary files of the module.

Python byte-code import uses

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.