os.path.isdir(path)異常
Window 10家庭中文版,Python 3.6.4,
當一個路徑以多個斜杠(/)或反斜杠字符(\\)結尾時,os.path.isdir(path)函數仍然將它們判斷為目錄:
>>> os.path.isdir(‘C:/Python36/Lib/sqlite3//‘)
True
>>> os.path.isdir(‘C:/Python36/Lib/sqlite3///‘)
True
>>> os.path.isdir(‘C:/Python36/Lib/sqlite3///////‘)
True
>>> os.path.isdir(‘C:\\Python36\\Lib\\sqlite3\\\\\\\\‘) # 8個反斜杠(轉義後是4個反斜杠 )
True
孤的判斷是返回False的,為何會如此?後續會繼續dig~
----
Python官文信息:
os.path.isdir(path)
Return True if path is an existing directory. This follows symbolic links, so both islink() and isdir() can be true for the same path.
path-like object
An object representing a file system path. A path-like object is either a str or bytes object representing a path, or an object implementing the os.PathLike protocol. An object that supports the os.PathLike protocol can be converted to a str or bytes file system path by calling the os.fspath() function; os.fsdecode() and os.fsencode() can be used to guarantee a str or bytes result instead, respectively. Introduced by PEP 519.
class os.PathLike
An abstract base class for objects representing a file system path, e.g. pathlib.PurePath.
PEP 519 -- Adding a file system path protocol
os.path.isdir(path)異常