Changeset 1523:c2a6894ec18d


Ignore:
Timestamp:
Jun 8, 2014, 6:23:10 PM (5 years ago)
Author:
Stefan Schwarzer <sschwarzer@…>
Branch:
default
Message:
Merged "Support for the `with` statement" into "Basics" for `FTPFile`
objects.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • doc/ftputil.txt

    r1522 r1523  
    10751075
    10761076``FTPFile`` objects are returned by a call to ``FTPHost.open``;
    1077 never use the constructor directly.
     1077never use the ``FTPFile`` constructor directly.
    10781078
    10791079The API of remote file-like objects are is modeled after the API of
     
    11211121Now, "text mode" follows the semantics in Python's ``io`` module.
    11221122
    1123 Support for the ``with`` statement
    1124 ``````````````````````````````````
    1125 
    1126 ``FTPFile`` objects can be used with the ``with`` statement::
     1123``FTPHost.open`` can also be used in a ``with`` statement::
    11271124
    11281125    import ftputil
    11291126
    1130     # Get an ``FTPHost`` object.
    1131     ...
    1132 
    1133     with host.open("new_file", "w") as fobj:
    1134         fobj.write("This is some text.")
    1135 
    1136 At the end of the ``with`` block, the file will be closed
     1127    with ftputil.FTPHost(...) as ftp_host:
     1128        ...
     1129        with ftp_host.open("new_file", "w", encoding="utf8") as fobj:
     1130            fobj.write("This is some text.")
     1131
     1132At the end of the ``with`` block, the remote file will be closed
    11371133automatically.
    11381134
Note: See TracChangeset for help on using the changeset viewer.