• 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: 行动通信基地台

  • 相关阅读:
    哈夫曼树
    MUI
    mui.init方法配置
    js中如何把字符串转化为对象、数组示例代码
    ( 转 )超级惊艳 10款HTML5动画特效推荐
    ( 转 ) 关于微信公众号,你不知道的15个小技巧
    h5预加载代码
    css3常用动画样式文件move.css
    iphone微信 h5页音乐自动播放
    sshpass: 用于非交互的ssh 密码验证
  • 原文地址:https://www.cnblogs.com/lshedward/p/9993778.html
Copyright © 2020-2023  润新知