Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

combine path python

# Python program to explain os.path.join() method
   
# importing os module
import os
 
# Path
path = "/home"
 
# Join various path components
print(os.path.join(path, "User/Desktop", "file.txt"))
 
 
# Path
path = "User/Documents"
 
# Join various path components
print(os.path.join(path, "/home", "file.txt"))
 
# In above example '/home'
# represents an absolute path
# so all previous components i.e User / Documents
# are thrown away and joining continues
# from the absolute path component i.e / home.
 
 
# Path
path = "/User"
 
# Join various path components
print(os.path.join(path, "Downloads", "file.txt", "/home"))
 
# In above example '/User' and '/home'
# both represents an absolute path
# but '/home' is the last value
# so all previous components before '/home'
# will be discarded and joining will
# continue from '/home'
 
# Path
path = "/home"
 
# Join various path components
print(os.path.join(path, "User/Public/", "Documents", ""))
 
# In above example the last
# path component is empty
# so a directory separator ('/')
# will be put at the end
# along with the concatenated value
Comment

PREVIOUS NEXT
Code Example
Python :: how to round the values in a list 
Python :: how to add text in python turtle 
Python :: get statistics from list python 
Python :: add bearer token in python request 
Python :: how to add legend to python plot 
Python :: imshow grayscale 
Python :: python gui size 
Python :: pandas replace null with 0 
Python :: import apiview 
Python :: tkinter label border 
Python :: invert y axis python 
Python :: python unchain list 
Python :: drop unnamed column pandas 
Python :: set axis labels python 
Python :: start a simple http server python3 
Python :: python matplotlib log scale 
Python :: python check file extension 
Python :: ind vs wi 
Python :: how to change windows icon tkinter 
Python :: python create uuid 
Python :: mac install python 3.8 
Python :: opencv draw a point 
Python :: random letter generator python 
Python :: pandas drop all columns except certain ones 
Python :: plot nan values sns 
Python :: create a directory python 
Python :: how to open a software using python 
Python :: pandas add dataframe to the bottom of another 
Python :: convert pandas dataframe to spark dataframe 
Python :: count unique values numpy 
ADD CONTENT
Topic
Content
Source link
Name
9+9 =