diff --git a/README.md b/README.md index ee6fde4..1815989 100644 --- a/README.md +++ b/README.md @@ -1647,7 +1647,7 @@ from glob import glob ``` ### DirEntry -**Using scandir() instead of listdir() can significantly increase the performance of code that also needs file type information.** +**Unlike listdir(), scandir() returns DirEntry objects that cache isfile, isdir and on Windows also stat information, thus significantly increasing the performance of code that requires it.** ```python = scandir(path='.') # Returns DirEntry objects located at path. @@ -1703,32 +1703,32 @@ import os, shutil, subprocess * **Functions report OS related errors by raising either OSError or one of its [subclasses](#exceptions-1).** ```python -os.chdir() # Changes the current working directory. -os.mkdir(, mode=0o777) # Creates a directory. Mode is in octal. -os.makedirs(, mode=0o777) # Creates all directories in the path. +os.chdir() # Changes the current working directory. +os.mkdir(, mode=0o777) # Creates a directory. Mode is in octal. +os.makedirs(, mode=0o777) # Creates dirs in path. Also: `exist_ok=False`. ``` ```python -shutil.copy(from, to) # Copies the file. 'to' can exist or be a dir. -shutil.copytree(from, to) # Copies the directory. 'to' must not exist. +shutil.copy(from, to) # Copies the file. 'to' can exist or be a dir. +shutil.copytree(from, to) # Copies the directory. 'to' must not exist. ``` ```python -os.rename(from, to) # Renames/moves the file or directory. -os.replace(from, to) # Same, but overwrites 'to' if it exists. +os.rename(from, to) # Renames/moves the file or directory. +os.replace(from, to) # Same, but overwrites 'to' if it exists. ``` ```python -os.remove() # Deletes the file. -os.rmdir() # Deletes the empty directory. -shutil.rmtree() # Deletes the directory. +os.remove() # Deletes the file. +os.rmdir() # Deletes the empty directory. +shutil.rmtree() # Deletes the directory. ``` ### Shell Commands ```python - = os.popen('') # Executes command in sh/cmd and returns its stdout pipe. - = .read(size=-1) # Reads 'size' chars or until EOF. Also readline/s(). - = .close() # Closes the pipe. Returns None on success, int on error. + = os.popen('') # Executes command in sh/cmd and returns its stdout pipe. + = .read(size=-1) # Reads 'size' chars or until EOF. Also readline/s(). + = .close() # Closes the pipe. Returns None on success, int on error. ``` #### Sends '1 + 1' to the basic calculator and captures its output: diff --git a/index.html b/index.html index ed7c15d..feacb89 100644 --- a/index.html +++ b/index.html @@ -54,7 +54,7 @@
- +
@@ -1400,7 +1400,7 @@ value = args.<name>
<stat> = os.stat(<path>)            # Or: <DirEntry/Path>.stat()
 <real> = <stat>.st_mtime/st_size/…  # Modification time, size in bytes, …
 
-

DirEntry

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

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

DirEntry

Unlike listdir(), scandir() returns DirEntry objects that cache isfile, isdir and on Windows also stat information, thus significantly increasing the performance of code that requires it.

<iter> = scandir(path='.')          # Returns DirEntry objects located at path.
 <str>  = <DirEntry>.path            # Returns whole path as a string.
 <str>  = <DirEntry>.name            # Returns final component as a string.
 <file> = open(<DirEntry>)           # Opens the file and returns a file object.
@@ -1436,25 +1436,25 @@ value = args.<name>
 

Files and Directories

  • Paths can be either strings, Paths or DirEntry objects.
  • Functions report OS related errors by raising either OSError or one of its subclasses.
  • -
os.chdir(<path>)                    # Changes the current working directory.
-os.mkdir(<path>, mode=0o777)        # Creates a directory. Mode is in octal.
-os.makedirs(<path>, mode=0o777)     # Creates all directories in the path.
+
os.chdir(<path>)                 # Changes the current working directory.
+os.mkdir(<path>, mode=0o777)     # Creates a directory. Mode is in octal.
+os.makedirs(<path>, mode=0o777)  # Creates dirs in path. Also: `exist_ok=False`.
 
-
shutil.copy(from, to)               # Copies the file. 'to' can exist or be a dir.
-shutil.copytree(from, to)           # Copies the directory. 'to' must not exist.
+
shutil.copy(from, to)            # Copies the file. 'to' can exist or be a dir.
+shutil.copytree(from, to)        # Copies the directory. 'to' must not exist.
 
-
os.rename(from, to)                 # Renames/moves the file or directory.
-os.replace(from, to)                # Same, but overwrites 'to' if it exists.
+
os.rename(from, to)              # Renames/moves the file or directory.
+os.replace(from, to)             # Same, but overwrites 'to' if it exists.
 
-
os.remove(<path>)                   # Deletes the file.
-os.rmdir(<path>)                    # Deletes the empty directory.
-shutil.rmtree(<path>)               # Deletes the directory.
+
os.remove(<path>)                # Deletes the file.
+os.rmdir(<path>)                 # Deletes the empty directory.
+shutil.rmtree(<path>)            # Deletes the directory.
 
-

Shell Commands

<pipe> = os.popen('<command>')      # Executes command in sh/cmd and returns its stdout pipe.
-<str>  = <pipe>.read(size=-1)       # Reads 'size' chars or until EOF. Also readline/s().
-<int>  = <pipe>.close()             # Closes the pipe. Returns None on success, int on error.
+

Shell Commands

<pipe> = os.popen('<command>')   # Executes command in sh/cmd and returns its stdout pipe.
+<str>  = <pipe>.read(size=-1)    # Reads 'size' chars or until EOF. Also readline/s().
+<int>  = <pipe>.close()          # Closes the pipe. Returns None on success, int on error.
 

Sends '1 + 1' to the basic calculator and captures its output:

>>> subprocess.run('bc', input='1 + 1\n', capture_output=True, text=True)
@@ -2896,7 +2896,7 @@ $ pyinstaller script.py --add-data '<path>:.'  
  
 
   
 
diff --git a/parse.js b/parse.js
index c8a117e..f2e719e 100755
--- a/parse.js
+++ b/parse.js
@@ -69,12 +69,12 @@ const DATACLASS =
   '<tuple> = (\'<attr_name>\', <type> [, <default_value>])';
 
 const SHUTIL_COPY =
-  'shutil.copy(from, to)               # Copies the file. \'to\' can exist or be a dir.\n' +
-  'shutil.copytree(from, to)           # Copies the directory. \'to\' must not exist.\n';
+  'shutil.copy(from, to)            # Copies the file. \'to\' can exist or be a dir.\n' +
+  'shutil.copytree(from, to)        # Copies the directory. \'to\' must not exist.\n';
 
 const OS_RENAME =
-  'os.rename(from, to)                 # Renames/moves the file or directory.\n' +
-  'os.replace(from, to)                # Same, but overwrites \'to\' if it exists.\n';
+  'os.rename(from, to)              # Renames/moves the file or directory.\n' +
+  'os.replace(from, to)             # Same, but overwrites \'to\' if it exists.\n';
 
 const TYPE =
   '<class> = type(\'<class_name>\', <tuple_of_parents>, <dict_of_class_attributes>)';