zoukankan      html  css  js  c++  java
  • python中os.path 与sys.path

    常用的命令

    1 import sys
    2 import os.path
    3 
    4 this_dir = os.path.dirname(__file__)
    5 sys.path.insert(0, this_dir + '/..') 或 sys.path.append(this_dir)

    通过上述代码即首先获取当前目录,使用sys.path将要导入的package或module加入到PATH环境变量中。

    1.获取当前目录

    1   __file__    #是用来获得模块所在的路径的
    2   os.path.dirname()  ##返回目录路径

    2.sys.path —— 动态地改变Python搜索路径

    如果python中导入的package或module不在环境变量PATH中,那么可以使用sys.path将要导入的package或module加入到PATH环境变量中。

    1  sys.path.append(’引用模块的地址')   # 
    2  sys.path.insert(0, '引用模块的地址')  
  • 相关阅读:
    bash变量作用域问题
    grep sed awk find用法
    vim compare 比对
    python的位数问题
    mysql使用
    lua 学习
    iptables的使用
    地铁换乘
    NOJ 1063 生活的烦恼
    猴子的下落
  • 原文地址:https://www.cnblogs.com/lmh001/p/9957313.html
Copyright © 2011-2022 走看看