diff --git a/README.md b/README.md index 2624a70..0b280bf 100644 --- a/README.md +++ b/README.md @@ -1572,9 +1572,9 @@ from glob import glob ``` ```python - = path.exists('') - = path.isfile('') - = path.isdir('') + = path.basename('') # Returns final component. + = path.dirname('') # Returns path without final component. + = path.splitext('') # Splits on last period of final component. ``` ```python @@ -1582,20 +1582,14 @@ from glob import glob = glob('') # Returns paths matching the wildcard pattern. ``` -```python - = path.basename('') # Returns final component. - = path.dirname('') # Returns path without final component. - = path.splitext('')[1] # Returns final component's extension. -``` - -### Pathlib +### Path Object ```python from pathlib import Path ``` ```python - = Path('' [, '', , ...]) - = / '' / '' + = Path( [, ...]) # Accepts strings, Paths and DirEntry objects. + = / [/ ...] # One of the paths must be a Path object. ``` ```python @@ -1606,9 +1600,9 @@ from pathlib import Path ``` ```python - = .exists() - = .is_file() - = .is_dir() + = .exists() # Or: path.exists('') + = .is_file() # Or: path.isfile('') + = .is_dir() # Or: path.isdir('') ``` ```python @@ -1629,7 +1623,7 @@ from pathlib import Path ``` ### DirEntry -**Using scandir() instead of listdir() can significantly increase the performance of code that also needs file type or file attribute information.** +**Using scandir() instead of listdir() or iterdir() can significantly increase the performance of code that also needs file type or file attribute information.** ```python = os.scandir(path='.') # Returns DirEntry objects located at path. ``` diff --git a/index.html b/index.html index 2fa9965..fc3799e 100644 --- a/index.html +++ b/index.html @@ -1451,31 +1451,27 @@ value = args.<name> <str> = path.join('<path>', ...) # Joins two or more pathname components. <str> = path.abspath('<path>') # Return an absolute path. -
<bool> = path.exists('<path>')
-<bool> = path.isfile('<path>')
-<bool> = path.isdir('<path>')
+
<str>  = path.basename('<path>')    # Returns final component.
+<str>  = path.dirname('<path>')     # Returns path without final component.
+<tup.> = path.splitext('<path>')    # Splits on last period of final component.
 
<list> = listdir('<path>')          # Returns filenames located at path.
 <list> = glob('<pattern>')          # Returns paths matching the wildcard pattern.
 
-
<str>  = path.basename('<path>')    # Returns final component.
-<str>  = path.dirname('<path>')     # Returns path without final component.
-<str>  = path.splitext('<path>')[1] # Returns final component's extension.
-
-

Pathlib

from pathlib import Path
+

Path Object

from pathlib import Path
 
-
<Path> = Path('<path>' [, '<path>', <Path>, ...])
-<Path> = <Path> / '<dir>' / '<file>'
+
<Path> = Path(<path> [, ...])       # Accepts strings, Paths and DirEntry objects.
+<Path> = <path> / <path> [/ ...]    # One of the paths must be a Path object.
 
<Path> = Path()                     # Or: Path('.')
 <Path> = Path.cwd()                 # Returns absolute cwd. Or: Path().resolve()
 <Path> = <Path>.resolve()           # Returns absolute Path without symlinks.
 <Path> = <Path>.parent              # Returns Path without final component.
 
-
<bool> = <Path>.exists()
-<bool> = <Path>.is_file()
-<bool> = <Path>.is_dir()
+
<bool> = <Path>.exists()            # Or: path.exists('<path>')
+<bool> = <Path>.is_file()           # Or: path.isfile('<path>')
+<bool> = <Path>.is_dir()            # Or: path.isdir('<path>')
 
<iter> = <Path>.iterdir()           # Returns dir contents as relative (not true) Path objects.
 <iter> = <Path>.glob('<pattern>')   # Returns relative Paths matching the wildcard pattern.
@@ -1488,7 +1484,7 @@ value = args.<name>
 
<file> = open(<Path>)               # Opens the file and returns a file object.
 
-

DirEntry

Using scandir() instead of listdir() can significantly increase the performance of code that also needs file type or file attribute information.

<iter> = os.scandir(path='.')       # Returns DirEntry objects located at path.
+

DirEntry

Using scandir() instead of listdir() or iterdir() can significantly increase the performance of code that also needs file type or file attribute information.

<iter> = os.scandir(path='.')       # Returns DirEntry objects located at path.