"Python Route 27" VARs () contains the global variable object

Source: Internet
Author: User
Tags vars

One, print (VARs ()) output results are as follows:

{' __name__ ': ' __main__ ',

' __doc__ ': None,

' __package__ ': None,

' __loader__ ': <_frozen_importlib_external. Sourcefileloader object at 0x0000014be5cba470>

' __spec__ ': None,

' __annotations__ ': {},

' __builtins__ ': <module ' builtins ' (built-in);

' __file__ ': ' e:/python_code/2/13day/index.py ',

' __cached__ ': None}

Among the more commonly used are:

__doc__ print a file comment, the contents of the three quotation marks at the beginning of the. py file

__file__ to print the full path name of the current PY file

__PACKAGE__ the package where the import file is located, that is, the folder name where the py file is imported, and the folder hierarchy. Interval, such as Lib.test

__cached__ Python3, the full path of the. pyc file that the cache file, import file executes.

__NAME__ returns __main__ if the current py file is running, returns the folder path where the current import file resides if another file import runs

Therefore, in order to prevent the import of modules to run directly, you can use __name__ = = __main__ to judge:

"Python Route 27" VARs () contains the global variable object

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.