• python寻找模块的路径顺序


    >>> import sys
    >>> sys.path
    ['', '/Library/Frameworks/Python.framework/Versions/3.7/lib/python37.zip', '/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7', '/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/lib-dynload', '/Users/liangshaohua/Library/Python/3.7/lib/python/site-packages', '/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages']

     python解释器会从当前目录开始,从左到右按顺序查找。前面的我们基本不用,我们经常用的也就是自己写的和site-packages,第三方和内置的都在site-packages里面。

    增加模块路径

    >>> sys.path.append('module_practice')
    >>> import my_module
    ['', '/Library/Frameworks/Python.framework/Versions/3.7/lib/python37.zip', '/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7', '/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/lib-dynload', '/Users/liangshaohua/Library/Python/3.7/lib/python/site-packages', '/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages', 'module_practice']

    删除模块路径

    >>> del sys.path[-1]
    >>> sys.path
    ['', '/Library/Frameworks/Python.framework/Versions/3.7/lib/python37.zip', '/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7', '/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/lib-dynload', '/Users/liangshaohua/Library/Python/3.7/lib/python/site-packages', '/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages']

    注意:增加也只是在当前程序整个程序的运行过程中加了,退出就没有了。

    site  [saɪt]  详细X
    基本翻译
    n. 地点;位置;场所
    vt. 设置;为…选址
    网络释义
    Site: 站点
    Construction Site: 建筑工地
    Cell site: 行动通信基地台

  • 相关阅读:
    深度学习网络压缩简单介绍
    骨架提取与分水岭算法
    高级形态学处理
    iview @change添加自定义参数
    设置axios拦截器,promise抛出的异常处理
    js 网页跳转
    js 加减法
    vue重新渲染组件(重置或者更新)
    Laravel里firstOrCreate、firstOrNew、updateOrCreate 方法使用
    算法
  • 原文地址:https://www.cnblogs.com/lshedward/p/9993778.html
Copyright © 2020-2023  润新知