Going one directory behind using OS in Python -
i have file sample.py in bin folder. path of bin - /username/packagename/bin
so when doing, dir = os.getcwd(), gives me path of bin(mentioned above).
so, there way can go 1 directory behind, /username/packagename ??
if want path of directory, 1 directory behind current working directory, can use os.path.join()
relative paths , convert them absolute path (if necessary) using os.path.abspath
. example -
one_dir_up_path = os.path.abspath(os.path.join(os.getcwd(),'..'))
Comments
Post a Comment