Python joining current directory and parent directory with os.path.join

You can use normpath, realpath or abspath:

import os
goal_dir = os.path.join(os.getcwd(), "../../my_dir")
print goal_dir  # prints C:/here/I/am/../../my_dir
print os.path.normpath(goal_dir)  # prints C:/here/my_dir
print os.path.realpath(goal_dir)  # prints C:/here/my_dir
print os.path.abspath(goal_dir)  # prints C:/here/my_dir

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)