0
1193
If you have a file name file1.txt in location /root/pythoneasy/, then the absolute path of the file is /root/pythoneasy/file1.txt
import os
directory_name = os.path.dirname('/root/pythoneasy/file1.txt')
print(directory_name ) # will print '/root/pythoneasy'
/root/pythoneasy
If the relative path will be used i.e. '../pythoneasy/file1.txt', it will print relative path not absolute path
import os
directory_name = os.path.dirname('../pythoneasy/file1.txt')
print(directory_name) # will print '../pythoneasy'
../pythoneasy
Comment here