zoukankan      html  css  js  c++  java
  • 模块小结

    1.import 模块名(文件)
        导入模块
    2.查看模块内的方法
        dir(模块名)
    3.if __name__ == "__main__":
        需要测试的语句
    4.from 模块名 import 方法/属性/* 
        再使用时 使用 方法即可 不再使用模块名.方法
    5.使用 __all__ = ["方法1","方法2","属性名1","属性名2"]
        在导入 * 时,只导入该 all 中的方法或属性
        在 __init__.py 文件第一行
    6.import 模块名(文件) as 模块别名
    7.搜索模块:
        import sys
        sys.path.append(r'绝对路径')
            绝对路径指 导入的模块的 文件夹的位置
    
    a.py 程序:
    
    import linecache
    print(linecache.__file__)
    def show( ):
        print("我是 0411 的模块")
    
    程序:
    import linecache
    # 导入模块
    print(dir(linecache))
    # 查看都具有哪些方法
    '''
    ['__all__', '__builtins__', '__cached__', 
    '__doc__', '__file__', '__loader__', '__name__', 
    '__package__', '__spec__', 'cache', 'checkcache', 
    'clearcache', 'functools', 'getline', 'getlines', 
    'lazycache', 'os', 'sys', 'tokenize', 'updatecache']
    '''
    linecache.__file__
    # 查看模块地址
    # F:Python IDLEliblinecache.py
    from math import pi 
    
    import sys
    sys.path.append(r'D:见解PythonPython代码学习411')
    if __name__ == "__main__":
        # 执行文件时,进行测试
        print(linecache.__file__)
        # F:Python IDLEliblinecache.py
        
        print(pi)
        # 使用 math 中的 pi 属性
        # 3.141592653589793
        import a
        # 导入 0411 的 a.py 文件
        a.show()
        # 我是 0411 的模块

    2020-04-12

  • 相关阅读:
    测试开发系列之Python开发mock接口(三)
    测试开发系列之Python开发mock接口(二)
    测试开发系列之Python开发mock接口(一)
    python单元测试unittest
    Linux–Nginx攻略
    cookies和session
    Selenium-------ActionChainApi接口详解
    Selenium-----wait的三种等待
    Selenium-Switch与SelectApi接口
    app token session rsp
  • 原文地址:https://www.cnblogs.com/hany-postq473111315/p/12684404.html
Copyright © 2011-2022 走看看