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

Popular posts from this blog

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -