Best way to ensure user calls methods in correct order?
Neil Cerutti
neilc at norwich.edu
Fri Jun 23 14:28:17 EDT 2017
On 2017-06-23, Gregory Ewing <greg.ewing at canterbury.ac.nz> wrote:
> Steve D'Aprano wrote:
>> There are a very few exceptions to this rule of thumb, such as
>> opening connections to databases or files or similar.
>
> Another way to handle that is to have the connection method
> return another object that has the methods that should only be
> called for active connections. That way it's not possible to do
> things out of sequence.
It's like a bidirectional iterator in C++, except in reverse it's
random access. An iterator that can't easily be modeled with a
generator in Python is going to feel awkward.
--
Neil Cerutti
More information about the Python-list
mailing list