python引用模块

python中模块分为内置模块、第三方模块和自定义模块;模块本质上就是py文件或者存放py文件文件夹,本文主要讲的是python中模块的引用。

python中引用模块有两种方式:第一种是使用import直接导入模块;第二种是使用from ** import **。

  • import 模块

    import 模块1          模块1.函数()

    import 模块1.模块2.模块3    模块1.模块2.模块2.函数()

  • from ** import **

    from 模块.模块 import 函数    函数()

    from 模块.模块 import 函数 as f  f()

    from 模块.模块 import *      函数1() 函数2()

    from 模块 import 模块       模块.函数()

    from 模块import 模块 as m    m.函数()

  • 特殊情况

    import 文件夹  (加载__init__.py)

 

    from 文件 import *

 

posted @ 2021-08-03 14:59  zchang  阅读(558)  评论(0)    收藏  举报