Built-in function __ function in each PY file

Source: Internet
Author: User
Tags vars
# 。 /usr/bin/env python
#-*-Coding:utf-8-*-
"""
Each py file has its own built-in function
Print (VARs ()) to view
If this module is a directory when you import the module, you need to create a __init__ file in it.
"""

#print (VARs ())
#常用的函数内置函数
Print (__name__) #如果是主文件, __name__ = "__main__", otherwise equal to module name
print (__doc__)  #没有则为None
Print (__file__) # Refers to the current file path with Os.path.dirname usage ratio large from

python11.bin import AA  #aa在与bin同级的lib下面

print (aa.__package__)  #当前文件为None, import additional files: Specify the package to which the file is located, with. Delimited.
print (aa.__cached__) #不加aa是当前文件的, and the current file is none. Otherwise, the other files

that are imported



#要求:
#在python11下面有两个同级文件, Lib and bin, require the OS module method to allow the current directory to be imported into the bin inside the AA
Import Sys,os
p1 = Os.path.dirname (Os.path.dirname (__file__)) #得到父级目录
p2 = "Bin" Result
= Os.path.join ( P1,P2)  #拼接目录
Print (Result)
sys.path.append (Result) #添加到搜索路径的环境变量里面 to
i in Sys.path:
    Print (i)
import AA
print (AA.F ())  #使用的时候要用模块名加点 (example: AA.F ())




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.