python 文件路径

  1. 获取运行文件路径 

@staticmethod

def get_run_dir():

    script_path = sys.argv[0]

    full_path = ""

    if script_path[0] != "/":

        full_path = "%s/%s" % (os.getcwd(), script_path)

    else:

        full_path = script_path

    return os.path.dirname(full_path)
  1.  获取当前文件路径

@staticmethod

def get_current_dir():

    current_filepath = os.path.abspath(__file__)

    return os.path.dirname(current_filepath)

 

你可能感兴趣的:(python,python,path)