From 8ebaf8f6e674ef3e7296f93030163757d561d06e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Sun, 22 Dec 2019 16:07:46 +0100 Subject: [PATCH] Working on path --- README.md | 12 +++++++++++- index.html | 12 ++++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 7e32576..2624a70 100644 --- a/README.md +++ b/README.md @@ -1567,6 +1567,8 @@ from glob import glob ```python = getcwd() # Returns the current working directory. + = path.join('', ...) # Joins two or more pathname components. + = path.abspath('') # Return an absolute path. ``` ```python @@ -1580,6 +1582,12 @@ 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 ```python from pathlib import Path @@ -1592,8 +1600,9 @@ from pathlib import Path ```python = Path() # Or: Path('.') + = Path.cwd() # Returns absolute cwd. Or: Path().resolve() = .resolve() # Returns absolute Path without symlinks. - = .parent # Returns path without final component. + = .parent # Returns Path without final component. ``` ```python @@ -1620,6 +1629,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.** ```python = os.scandir(path='.') # Returns DirEntry objects located at path. ``` diff --git a/index.html b/index.html index 29c4bd9..2fa9965 100644 --- a/index.html +++ b/index.html @@ -1448,6 +1448,8 @@ value = args.<name>
<str>  = getcwd()                   # Returns the current working directory.
+<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>')
@@ -1456,6 +1458,10 @@ value = args.<name>
 
<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
 
@@ -1463,8 +1469,9 @@ value = args.<name> <Path> = <Path> / '<dir>' / '<file>'
<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.
+<Path> = <Path>.parent              # Returns Path without final component.
 
<bool> = <Path>.exists()
 <bool> = <Path>.is_file()
@@ -1481,9 +1488,10 @@ value = args.<name>
 
<file> = open(<Path>)               # Opens the file and returns a file object.
 
-

DirEntry

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

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.
 
+
<bool> = <DirEntry>.is_file()
 <bool> = <DirEntry>.is_dir()