From bb44b25b23b5d888852bf94203c1ec5c3cb06108 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Wed, 15 Jun 2022 02:53:31 +0200 Subject: [PATCH] Command line arguments, OS Commands --- README.md | 8 +++----- index.html | 19 +++++++++---------- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 92254ab..6a7a184 100644 --- a/README.md +++ b/README.md @@ -1546,7 +1546,7 @@ value = args. * **Use `'help='` to set argument description that will be displayed in help message.** * **Use `'default='` to set the default value.** -* **Use `'type=FileType()'` for files. Accepts 'encoding', but 'newline' is always None.** +* **Use `'type=FileType()'` for files. Accepts 'encoding', but not 'newline'.** Open @@ -1701,10 +1701,6 @@ OS Commands import os, shutil, subprocess ``` -### 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](#exceptions-1).** - ```python os.chdir() # Changes the current working directory. os.mkdir(, mode=0o777) # Creates a directory. Mode is in octal. @@ -1726,6 +1722,8 @@ os.remove() # Deletes the file. os.rmdir() # Deletes the empty directory. shutil.rmtree() # Deletes the directory. ``` +* **Paths can be either strings, Paths or DirEntry objects.** +* **Functions report OS related errors by raising either OSError or one of its [subclasses](#exceptions-1).** ### Shell Commands ```python diff --git a/index.html b/index.html index 2007bd3..3b58039 100644 --- a/index.html +++ b/index.html @@ -54,7 +54,7 @@
- +
@@ -1322,7 +1322,7 @@ value = args.<name>
  • Use 'help=<str>' to set argument description that will be displayed in help message.
  • Use 'default=<el>' to set the default value.
  • -
  • Use 'type=FileType(<mode>)' for files. Accepts 'encoding', but 'newline' is always None.
  • +
  • Use 'type=FileType(<mode>)' for files. Accepts 'encoding', but not 'newline'.

#Open

Opens the file and returns a corresponding file object.

<file> = open(<path>, mode='r', encoding=None, newline=None)
 
@@ -1435,15 +1435,10 @@ value = args.<name>

#OS Commands

import os, shutil, subprocess
 
-

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.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 path's dirs. 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.
 
@@ -1454,6 +1449,10 @@ os.replace(from, to) # Same, but overwrit os.rmdir(<path>) # Deletes the empty directory. shutil.rmtree(<path>) # Deletes the directory. +
    +
  • Paths can be either strings, Paths or DirEntry objects.
  • +
  • Functions report OS related errors by raising either OSError or one of its subclasses.
  • +

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.
@@ -2903,7 +2902,7 @@ $ pyinstaller script.py --add-data '<path>:.'