父级目录的获取:只用加上os.path.dirname(当前路径)即可
import sys
import os
os.path.realpath(__file__) # 获取当前路径
os.path.dirname(os.path.realpath(__file__)) # 获取当前路径的父级路径
GRANDFA = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) # 获取父路径的父路径
sys.path.append(GRANDFA ) # 将祖父路径加入sys中
# 依次类推。
os.path.pardir是父目录,os.path.abspath是绝对路径