| LEFT | RIGHT |
| (no file at all) | |
| 1 :mod:`shutil` --- High-level file operations | 1 :mod:`shutil` --- High-level file operations |
| 2 ============================================ | 2 ============================================ |
| 3 | 3 |
| 4 .. module:: shutil | 4 .. module:: shutil |
| 5 :synopsis: High-level file operations, including copying. | 5 :synopsis: High-level file operations, including copying. |
| 6 .. sectionauthor:: Fred L. Drake, Jr. <fdrake@acm.org> | 6 .. sectionauthor:: Fred L. Drake, Jr. <fdrake@acm.org> |
| 7 .. partly based on the docstrings | 7 .. partly based on the docstrings |
| 8 | 8 |
| 9 .. index:: | 9 .. index:: |
| 10 single: file; copying | 10 single: file; copying |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 | 40 |
| 41 Copy the contents of the file-like object *fsrc* to the file-like object *fds
t*. | 41 Copy the contents of the file-like object *fsrc* to the file-like object *fds
t*. |
| 42 The integer *length*, if given, is the buffer size. In particular, a negative | 42 The integer *length*, if given, is the buffer size. In particular, a negative |
| 43 *length* value means to copy the data without looping over the source data in | 43 *length* value means to copy the data without looping over the source data in |
| 44 chunks; by default the data is read in chunks to avoid uncontrolled memory | 44 chunks; by default the data is read in chunks to avoid uncontrolled memory |
| 45 consumption. Note that if the current file position of the *fsrc* object is n
ot | 45 consumption. Note that if the current file position of the *fsrc* object is n
ot |
| 46 0, only the contents from the current file position to the end of the file wi
ll | 46 0, only the contents from the current file position to the end of the file wi
ll |
| 47 be copied. | 47 be copied. |
| 48 | 48 |
| 49 | 49 |
| 50 .. function:: copyfile(src, dst, symlinks=False) | 50 .. function:: copyfile(src, dst, *, follow_symlinks=True) |
| 51 | 51 |
| 52 Copy the contents (no metadata) of the file named *src* to a file named | 52 Copy the contents (no metadata) of the file named *src* to a file named |
| 53 *dst* and return *dst*. *dst* must be the complete target file name; look at | 53 *dst* and return *dst*. *dst* must be the complete target file name; look at |
| 54 :func:`shutil.copy` for a copy that accepts a target directory path. If | 54 :func:`shutil.copy` for a copy that accepts a target directory path. If |
| 55 *src* and *dst* are the same files, :exc:`Error` is raised. | 55 *src* and *dst* are the same files, :exc:`Error` is raised. |
| 56 | 56 |
| 57 The destination location must be writable; otherwise, an :exc:`OSError` exce
ption | 57 The destination location must be writable; otherwise, an :exc:`OSError` exce
ption |
| 58 will be raised. If *dst* already exists, it will be replaced. Special files | 58 will be raised. If *dst* already exists, it will be replaced. Special files |
| 59 such as character or block devices and pipes cannot be copied with this | 59 such as character or block devices and pipes cannot be copied with this |
| 60 function. *src* and *dst* are path names given as strings. | 60 function. *src* and *dst* are path names given as strings. |
| 61 | 61 |
| 62 If *symlinks* is true and *src* is a symbolic link, a new symbolic link will | 62 If *follow_symlinks* is false and *src* is a symbolic link, a new symbolic li
nk will |
| 63 be created instead of copying the file *src* points to. | 63 be created instead of copying the file *src* points to. |
| 64 | 64 |
| 65 .. versionchanged:: 3.3 | 65 .. versionchanged:: 3.3 |
| 66 :exc:`IOError` used to be raised instead of :exc:`OSError`. | 66 :exc:`IOError` used to be raised instead of :exc:`OSError`. |
| 67 Added *symlinks* argument. | 67 Added *follow_symlinks* argument. |
| 68 | 68 |
| 69 .. versionchanged:: 3.3 | 69 .. versionchanged:: 3.3 |
| 70 Added return of the *dst*. | 70 Added return of the *dst*. |
| 71 | 71 |
| 72 .. function:: copymode(src, dst, symlinks=False) | 72 .. function:: copymode(src, dst, *, follow_symlinks=True) |
| 73 | 73 |
| 74 Copy the permission bits from *src* to *dst*. The file contents, owner, and | 74 Copy the permission bits from *src* to *dst*. The file contents, owner, and |
| 75 group are unaffected. *src* and *dst* are path names given as strings. If | 75 group are unaffected. *src* and *dst* are path names given as strings. If |
| 76 *symlinks* is true, *src* a symbolic link and the operating system supports | 76 *follow_symlinks* is false, *src* a symbolic link and the operating system su
pports |
| 77 modes for symbolic links (for example BSD-based ones), the mode of the link | 77 modes for symbolic links (for example BSD-based ones), the mode of the link |
| 78 will be copied. | 78 will be copied. |
| 79 | 79 |
| 80 .. versionchanged:: 3.3 | 80 .. versionchanged:: 3.3 |
| 81 Added *symlinks* argument. | 81 Added *follow_symlinks* argument. |
| 82 | 82 |
| 83 .. function:: copystat(src, dst, symlinks=False) | 83 .. function:: copystat(src, dst, *, follow_symlinks=True) |
| 84 | 84 |
| 85 Copy the permission bits, last access time, last modification time, and flags | 85 Copy the permission bits, last access time, last modification time, and flags |
| 86 from *src* to *dst*. The file contents, owner, and group are unaffected. *s
rc* | 86 from *src* to *dst*. The file contents, owner, and group are unaffected. *s
rc* |
| 87 and *dst* are path names given as strings. If *src* and *dst* are both | 87 and *dst* are path names given as strings. If *src* and *dst* are both |
| 88 symbolic links and *symlinks* true, the stats of the link will be copied as | 88 symbolic links and *follow_symlinks* false, the stats of the link will be cop
ied as |
| 89 far as the platform allows. | 89 far as the platform allows. |
| 90 | 90 |
| 91 .. versionchanged:: 3.3 | 91 .. versionchanged:: 3.3 |
| 92 Added *symlinks* argument. | 92 Added *follow_symlinks* argument. |
| 93 | 93 |
| 94 .. function:: copy(src, dst, symlinks=False) | 94 .. function:: copy(src, dst, *, follow_symlinks=True) |
| 95 | 95 |
| 96 Copy the file *src* to the file or directory *dst* and return the file's | 96 Copy the file *src* to the file or directory *dst* and return the file's |
| 97 destination. If *dst* is a directory, a | 97 destination. If *dst* is a directory, a |
| 98 file with the same basename as *src* is created (or overwritten) in the | 98 file with the same basename as *src* is created (or overwritten) in the |
| 99 directory specified. Permission bits are copied. *src* and *dst* are path | 99 directory specified. Permission bits are copied. *src* and *dst* are path |
| 100 names given as strings. If *symlinks* is true, symbolic links won't be | 100 names given as strings. If *follow_symlinks* is false, symbolic links won't
be |
| 101 followed but recreated instead -- this resembles GNU's :program:`cp -P`. | 101 followed but recreated instead -- this resembles GNU's :program:`cp -P`. |
| 102 | 102 |
| 103 .. versionchanged:: 3.3 | 103 .. versionchanged:: 3.3 |
| 104 Added *symlinks* argument. | 104 Added *follow_symlinks* argument. |
| 105 | 105 |
| 106 .. versionchanged:: 3.3 | 106 .. versionchanged:: 3.3 |
| 107 Added return of the *dst*. | 107 Added return of the *dst*. |
| 108 | 108 |
| 109 .. function:: copy2(src, dst, symlinks=False) | 109 .. function:: copy2(src, dst, *, follow_symlinks=True) |
| 110 | 110 |
| 111 Similar to :func:`shutil.copy`, including that the destination is | 111 Similar to :func:`shutil.copy`, including that the destination is |
| 112 returned, but metadata is copied as well. This is | 112 returned, but metadata is copied as well. This is |
| 113 similar to the Unix command :program:`cp -p`. If *symlinks* is true, | 113 similar to the Unix command :program:`cp -p`. If *follow_symlinks* is false, |
| 114 symbolic links won't be followed but recreated instead -- this resembles | 114 symbolic links won't be followed but recreated instead -- this resembles |
| 115 GNU's :program:`cp -P`. | 115 GNU's :program:`cp -P`. |
| 116 | 116 |
| 117 .. versionchanged:: 3.3 | 117 .. versionchanged:: 3.3 |
| 118 Added *symlinks* argument, try to copy extended file system attributes | 118 Added *follow_symlinks* argument, try to copy extended file system attribu
tes |
| 119 too (currently Linux only). | 119 too (currently Linux only). |
| 120 | 120 |
| 121 .. versionchanged:: 3.3 | 121 .. versionchanged:: 3.3 |
| 122 Added return of the *dst*. | 122 Added return of the *dst*. |
| 123 | 123 |
| 124 .. function:: ignore_patterns(\*patterns) | 124 .. function:: ignore_patterns(\*patterns) |
| 125 | 125 |
| 126 This factory function creates a function that can be used as a callable for | 126 This factory function creates a function that can be used as a callable for |
| 127 :func:`copytree`\'s *ignore* argument, ignoring files and directories that | 127 :func:`copytree`\'s *ignore* argument, ignoring files and directories that |
| 128 match one of the glob-style *patterns* provided. See the example below. | 128 match one of the glob-style *patterns* provided. See the example below. |
| (...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 538 size used by many terminal emulators. | 538 size used by many terminal emulators. |
| 539 | 539 |
| 540 The value returned is a named tuple of type :class:`os.terminal_size`. | 540 The value returned is a named tuple of type :class:`os.terminal_size`. |
| 541 | 541 |
| 542 See also: The Single UNIX Specification, Version 2, | 542 See also: The Single UNIX Specification, Version 2, |
| 543 `Other Environment Variables`_. | 543 `Other Environment Variables`_. |
| 544 | 544 |
| 545 .. _`Other Environment Variables`: | 545 .. _`Other Environment Variables`: |
| 546 http://pubs.opengroup.org/onlinepubs/7908799/xbd/envvar.html#tag_002_003 | 546 http://pubs.opengroup.org/onlinepubs/7908799/xbd/envvar.html#tag_002_003 |
| 547 | 547 |
| LEFT | RIGHT |