From 533836d58b03fd163f652a172e84e28763867bc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Tue, 10 Sep 2019 16:45:43 +0200 Subject: [PATCH] Command execution --- README.md | 15 +++++++++++---- index.html | 15 +++++++++------ parse.js | 8 ++++++-- 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 77f25b4..36ca716 100644 --- a/README.md +++ b/README.md @@ -1177,7 +1177,7 @@ class MyOpen(): Hello World! ``` -#### List of existing context managers: +#### List of covered context managers: ```python with open('') as file: ... with wave.open('') as wave_file: ... @@ -1615,12 +1615,14 @@ Command Execution ```python import os, shutil - = os.getcwd() # Returns the current working directory. +``` + +```python os.chdir() # Changes current working directory. +os.mkdir(, mode=0o777) # Creates a directory. ``` ```python -shutil.copy(from, to) # Copies the file. os.rename(from, to) # Renames the file or directory. os.replace(from, to) # Same, but overwrites 'to' if it exists. ``` @@ -1632,7 +1634,12 @@ shutil.rmtree() # Deletes the entire directory tree. ``` ```python -os.mkdir(, mode=0o777) # Creates a directory. +shutil.copy(from, to) # Copies the file. +shutil.copytree(from, to) # Copies the entire directory tree. +``` + +```python + = os.getcwd() # Returns the current working directory. = os.scandir(path='.') # Returns os.DirEntry objects located at path. ``` diff --git a/index.html b/index.html index 24d7daa..e6fbf15 100644 --- a/index.html +++ b/index.html @@ -1114,7 +1114,7 @@ Z = dataclasses.make_dataclass('Z', [... print(file.read()) Hello World! -

List of existing context managers:

with open('<path>') as file: ...
+

List of covered context managers:

with open('<path>') as file: ...
 with wave.open('<path>') as wave_file: ...
 with memoryview(<bytes/bytearray/array>) as view: ...
 with concurrent.futures.ThreadPoolExecutor() as executor: ...
@@ -1470,21 +1470,24 @@ value = args.<name>
 
  • Paths can be either strings, Paths, or DirEntry objects.
  • Functions report OS related errors by raising either OSError or one of its subclasses.
  • import os, shutil
    -<str> = os.getcwd()                # Returns the current working directory.
    -os.chdir(<path>)                   # Changes current working directory.
     
    -
    shutil.copy(from, to)              # Copies the file.
    -os.rename(from, to)                # Renames the file or directory.
    +
    os.chdir(<path>)                   # Changes current working directory.
    +os.mkdir(<path>, mode=0o777)       # Creates a directory.
    +
    +
    os.rename(from, to)                # Renames 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 empty directory.
     shutil.rmtree(<path>)              # Deletes the entire directory tree.
     
    -
    os.mkdir(<path>, mode=0o777)       # Creates a directory.
    +
    shutil.copy(from, to)              # Copies the file.
    +shutil.copytree(from, to)          # Copies the entire directory tree.
    +
    +
    <str>  = os.getcwd()               # Returns the current working directory.
     <iter> = os.scandir(path='.')      # Returns os.DirEntry objects located at path.
     

    DirEntry:

    <bool> = <DirEntry>.is_file()
    diff --git a/parse.js b/parse.js
    index 8b546b1..7376dae 100755
    --- a/parse.js
    +++ b/parse.js
    @@ -194,11 +194,14 @@ const DIAGRAM_7_B =
       '┃ count()    │          │            │          │      ✓       ┃\n' +
       '┗━━━━━━━━━━━━┷━━━━━━━━━━┷━━━━━━━━━━━━┷━━━━━━━━━━┷━━━━━━━━━━━━━━┛\n';
     
    -const OS_RENAME = 
    -  'shutil.copy(from, to)              # Copies the file.\n' +
    +const OS_RENAME =
       'os.rename(from, to)                # Renames the file or directory.\n' +
       'os.replace(from, to)               # Same, but overwrites \'to\' if it exists.\n';
     
    +const SHUTIL_COPY = 
    +  'shutil.copy(from, to)              # Copies the file.\n' +
    +  'shutil.copytree(from, to)          # Copies the entire directory tree.\n';
    +
     const EVAL =
       '>>> from ast import literal_eval\n' +
       '>>> literal_eval(\'1 + 2\')\n' +
    @@ -316,6 +319,7 @@ function fixClasses() {
     
     function fixHighlights() {
       $(`code:contains(os.rename)`).html(OS_RENAME);
    +  $(`code:contains(shutil.copy)`).html(SHUTIL_COPY);
       $(`code:contains(ValueError: malformed node)`).html(EVAL);
       $(`code:contains(@lru_cache(maxsize=None))`).html(LRU_CACHE);
       $(`code:contains(, , )`).html(TYPE);