python get parent directory from file path code example
Example 1: python get parent directory
import os.path
os.path.dirname('C:\Program Files')
Example 2: python get parent directory
from pathlib import Path
Path('C:\Program Files').parent
Example 3: import file from parent directory python
import os, sys
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
# import ../db.py
import db