Python | os.path.dirname() method
Share
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
os.path.dirname() method in Python is used to get the directory name from the specified path.
path = '/home/User/Documents/file.txt' # Get the directory name # from the specified path dirname = os.path.dirname(path) # Print the directory name print(dirname) OUTPUT: /home/User/Documents