• python基础:搜索路径


    如何将写好的脚本或者是模块加入python的搜索路径?

    >>>import sys
    >>> sys.path
    ['', '/Library/Frameworks/Python.framework/Versions/3.4/lib/python34.zip', '/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4', '/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/plat-darwin', '/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/lib-dynload', '/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages']
    #出来的是一个路径列表,python会从这里搜索路径,其中模块应该存放在/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages
    
    >>>sys.path.append("/desktop/python3.4/test.py")  
    #把test.py的路径加入python搜索路径里去
    >>>sys.path
    ['', '/Library/Frameworks/Python.framework/Versions/3.4/lib/python34.zip', '/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4', '/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/plat-darwin', '/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/lib-dynload', '/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages','/desktop/python3.4/test.py']
    >>>import test
    "Hellow world"
    

      

  • 相关阅读:
    hihocoder-Week216-Gas Stations
    hihocoder-1740-替换函数
    hihocoder-1732-1-偏差排列
    hihocoder-Week200-Shorteniring Sequence
    hihocoder-1720-小数数字
    hihocoder-Week197-逆序单词
    hihocoder-Week195-奖券兑换
    hihocoder-Week184-满减优惠
    word ladder-leetcode
    数的划分
  • 原文地址:https://www.cnblogs.com/alan-babyblog/p/5148696.html
Copyright © 2020-2023  润新知