获取文件路径
当前文件路径
import os
import sys
#获取当前文件路径
On_path = os.path.realpath(__file__)
print("当前文件路径:" + On_path)
#获取当前文件的父路径
parent_path = os.path.dirname(os.path.realpath(__file__))
print("当前文件父目录:" + parent_path)
#当前文件父目录的父目录
garder = os.path.dirname(parent_path)
print("当前文件父目录的父目录:" + garder)
# 获取文件名
print("获取文件名" + os.path.basename(os.path.realpath(__file__)))
# 当前运行路径
#当前运行路径
base_path = os.getcwd()
print("当前运行路径:" + base_path)
# 当前运行路径父路径
father_path = os.path.abspath(os.path.dirname(base_path) + os.path.sep + ".")
print("当前运行父路径" + father_path)
# 当前运行路径父路径的父路径
grader_father = os.path.abspath(os.path.dirname(base_path) + os.path.sep + "..")
print("当前运行路径父路径的父路径" + grader_father)
导入本地python包
import os
import sys
base_path = os.getcwd()
parent = os.path.dirname(os.path.realpath(__file__))
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from JM_class import JM