[ftputil] Implementing PEP 343: The 'with' statement

Stefan Schwarzer sschwarzer at sschwarzer.net
Wed Jul 23 21:05:53 CEST 2008


Hi Roger,

On 2008-07-23 14:29, Roger Demetrescu wrote:
> I have a suggestion: FTPHost could implement __enter__ and __exit__
> methods necessary to allow the use of `with` statement like that:
> 
> with ftputil.FTPHost('host', 'username', 'password') as host:
>     host.chdir('/some/path')
>     # do some more operations

I like the idea very much.

Two years ago, I asked for opinions on the minimal Python version
that should work with ftputil [1]. At that time, we concluded to
stick to Python 2.3 as requirement.

I had pondered how to make statements of newer Python versions
available without causing a syntax error or cyclic imports when
ftputil is run on older Python versions and thought it wouldn't
be possible (I now see a way).

In the special case of support of the with statement, however, it
seems that I can simply add __enter__ and __exit__ methods. I've
filed an issue on the topic under [2].

[1] http://codespeak.net/pipermail/ftputil/2006q3/000096.html
[2] http://ftputil.sschwarzer.net/trac/ticket/30

Stefan


More information about the ftputil mailing list