2017-11-05 4 views
1

OSライブラリのos.listdir の違いは何です:( ' ')os.listdirはos.listdir対()

の違いは何ですかos.listdir対()

('。')

彼らの両方は、しかし、同じ結果(アクティブディレクトリ内のすべてのリスト)を生成するように見える:

https://www.tutorialspoint.com/python/os_listdir.htm

はos.listdirが特に除外することを述べています「」ディレクトリに存在していても '..'と表示されます。どういう意味ですか?

答えて

2

機能的な違いはありません。docsを参照してください。あなたはos.listdir()'.'

0

で呼び出すときos.listdir()の定義は、この

os.listdir(path='.') 

パスのように、デフォルト値のように見えます。 listdir()の[dot]は、現在のディレクトリ&を参照していますが、listdir()に何も入力しないと、デフォルトで現在のディレクトリがリストされます。 はhelp os.listdirからここ

2

コードを入力してください:ある

listdir(path=None) 
    Return a list containing the names of the files in the directory. 

    path can be specified as either str or bytes. If path is bytes, 
     the filenames returned will also be bytes; in all other circumstances 
     the filenames returned will be str. 
    If path is None, uses the path='.'. 

は、os.listdir()os.listdir('.')と同じです。

[...]は、os.listdirは、特に「。」を除外しています。ディレクトリに存在していても '..'と表示されます。どういう意味ですか?

これは戻り値に関係します。 UNIXファイルシステムでは、すべてのディレクトリは、...のエントリ、 を持ちます。ここで、.はカレントディレクトリ、 および..は親ディレクトリです。 ドキュメントでは、これらのエントリはos.listdirによって返されるリストには含まれないことを示しています。

関連する問題