From 848809d0b96027bcfebfd32b0136fb25b276f2ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Tue, 3 Dec 2019 11:44:18 +0100 Subject: [PATCH] Path --- README.md | 21 ++++++++++++--------- index.html | 17 +++++++++-------- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 6c733bb..a66b1bc 100644 --- a/README.md +++ b/README.md @@ -1505,7 +1505,7 @@ Open ```python = open('', mode='r', encoding=None, newline=None) ``` -* **`'encoding=None'` means default encoding is used, which is platform dependent. Best practice is to use `'encoding="utf-8"'` whenever possible.** +* **`'encoding=None'` means that the default encoding is used, which is platform dependent. Best practice is to use `'encoding="utf-8"'` whenever possible.** * **`'newline=None'` means all different end of line combinations are converted to '\n' on read, while on write all '\n' characters are converted to system's default line separator.** * **`'newline=""'` means no conversions take place, but input is still broken into chunks by readline() and readlines() on either '\n', '\r' or '\r\n'.** @@ -1543,7 +1543,7 @@ Open ```python .write() # Writes a string or bytes object. -.writelines() # Writes a coll. of strings or bytes objects. +.writelines() # Writes a coll. of strings or bytes objects. .flush() # Flushes write buffer. ``` * **Methods do not add or strip trailing newlines, even writelines().** @@ -1566,10 +1566,14 @@ def write_to_file(filename, text): Path ---- ```python -from os import path, listdir +from os import getcwd, path, listdir from glob import glob ``` +```python + = getcwd() # Returns the current working directory. +``` + ```python = path.exists('') = path.isfile('') @@ -1633,6 +1637,11 @@ os.chdir() # Changes current working directory. os.mkdir(, mode=0o777) # Creates a directory. ``` +```python +shutil.copy(from, to) # Copies the file. +shutil.copytree(from, to) # Copies the entire directory tree. +``` + ```python os.rename(from, to) # Renames the file or directory. os.replace(from, to) # Same, but overwrites 'to' if it exists. @@ -1645,12 +1654,6 @@ shutil.rmtree() # Deletes the entire directory tree. ``` ```python -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 5292502..e052677 100644 --- a/index.html +++ b/index.html @@ -1395,7 +1395,7 @@ value = args.<name>
    -
  • 'encoding=None' means default encoding is used, which is platform dependent. Best practice is to use 'encoding="utf-8"' whenever possible.
  • +
  • 'encoding=None' means that the default encoding is used, which is platform dependent. Best practice is to use 'encoding="utf-8"' whenever possible.
  • 'newline=None' means all different end of line combinations are converted to '\n' on read, while on write all '\n' characters are converted to system's default line separator.
  • 'newline=""' means no conversions take place, but input is still broken into chunks by readline() and readlines() on either '\n', '\r' or '\r\n'.
@@ -1430,7 +1430,7 @@ value = args.<name> <str/bytes> = next(<file>) # Returns a line using buffer. Do not mix.
<file>.write(<str/bytes>)           # Writes a string or bytes object.
-<file>.writelines(<coll.>)          # Writes a coll. of strings or bytes objects.
+<file>.writelines(<collection>)     # Writes a coll. of strings or bytes objects.
 <file>.flush()                      # Flushes write buffer.
 
    @@ -1446,10 +1446,12 @@ value = args.<name> file.write(text) -

    #Path

    from os import path, listdir
    +

    #Path

    from os import getcwd, path, listdir
     from glob import glob
     
    +
    <str>  = getcwd()                   # Returns the current working directory.
    +
    <bool> = path.exists('<path>')
     <bool> = path.isfile('<path>')
     <bool> = path.isdir('<path>')
    @@ -1492,6 +1494,9 @@ value = args.<name>
     
    os.chdir(<path>)                    # Changes current working directory.
     os.mkdir(<path>, mode=0o777)        # Creates a directory.
     
    +
    shutil.copy(from, to)               # Copies the file.
    +shutil.copytree(from, to)           # Copies the entire directory tree.
    +
    os.rename(from, to)                 # Renames the file or directory.
     os.replace(from, to)                # Same, but overwrites 'to' if it exists.
     
    @@ -1499,11 +1504,7 @@ os.replace(from, to) # Same, but overw os.rmdir(<path>) # Deletes empty directory. shutil.rmtree(<path>) # Deletes the entire directory tree.
    -
    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.
    +
    <iter> = os.scandir(path='.')       # Returns os.DirEntry objects located at path.
     

    DirEntry:

    <bool> = <DirEntry>.is_file()
     <bool> = <DirEntry>.is_dir()