Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

os.path.dirname(__file__)

# Python program to explain os.path.dirname() method 
    
# importing os.path module 
import os.path
  
# Path
path = '/home/User/Documents'
  
# Get the directory name  
# from the specified path
dirname = os.path.dirname(path)
  
# Print the directory name  
print(dirname)
  
  
# 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)
  
  
# Path
path = 'file.txt'
  
# Get the directory name  
# from the specified path
dirname = os.path.dirname(path)
  
# Print the directory name  
print(dirname)
  
# In the above specified path 
# does not contains any
# directory so, 
# It will print Nothing
Comment

os.path.dirname(__file__)

/home/User
/home/User/Documents
Comment

PREVIOUS NEXT
Code Example
Python :: Convert Int to String Using str() function 
Python :: housie numbers using python 
Python :: python power 
Python :: python vars 
Python :: gunicorn django static files 
Python :: create database python 
Python :: gtts python 
Python :: STATPC 
Python :: install requests-html in linux 
Python :: python loop nest shorthand 
Python :: pandas group by decending 
Python :: how to get maximum value of number in python 
Python :: sum the contents of a list python 
Python :: why python stops after plt.show() 
Python :: how to remove groups/user_permissions from user admin panel in django,how to edit fields shown on user admin panel 
Python :: python ismatch 
Python :: python Python Program to Catch Multiple Exceptions in One Line 
Python :: pandas array of dataframes 
Python :: how to check mix types in pandas column 
Python :: Python __floordiv__ 
Python :: alphabeticallly 
Python :: position text in a box matplotlib 
Python :: Python Permutation without built-in function [itertools] for String 
Python :: command to install python3.6 on mac os 
Python :: pandas split column fixed width 
Python :: find email address pytho 
Python :: streamlit format_func example 
Python :: count unique values in python 
Python :: how to take dynamic input in python 
Python :: filter function in python 
ADD CONTENT
Topic
Content
Source link
Name
4+4 =