from os import listdir
from os.path import isfile, isdir, join
import os
b=[]
mypath = "D:\long\Desktop"
for f in listdir(mypath):
fullpath = join(mypath, f)
if isdir(fullpath):
b.append(fullpath)
print(fullpath)
打印出來的路徑是正常的一個斜線
但是如果打印b
路徑就會的一個斜線會變成兩個斜線
這要如何變回一個斜線啊?
你只要在路徑前加 r 就可以 把它由normal string 變成raw string.
from os import listdir
from os.path import isfile, isdir, join
import os
b=[]
mypath = r"D:\long\Desktop"
for f in listdir(mypath):
fullpath = join(mypath, f)
if isdir(fullpath):
b.append(fullpath)
print(fullpath)