“Kombinieren Sie Pfad Python” Code-Antworten

Kombinieren Sie Pfad 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
SharxNZ

Python schließen sich den Pfaden an

import os

# Join paths using OS import. Takes any amount of arguments
path = os.path.join('/var/www/public_html', './app/', ".\\my_file.json")

print(path) # /var/www/public_html/app/myfile.json
Allen

Ähnliche Antworten wie “Kombinieren Sie Pfad Python”

Fragen ähnlich wie “Kombinieren Sie Pfad Python”

Weitere verwandte Antworten zu “Kombinieren Sie Pfad Python” auf Python

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen