Help me pick an API design (OO vs functional)

Neil Cerutti neilc at
Tue Mar 26 15:13:30 CET 2013

On 2013-03-25, Mitya Sirenef <msirenef at> wrote:
> I think I would prefer context managers. I don't think it's a
> big problem for win users because this behaviour would be one
> of the first things documented in the start guide and would be
> all over example scripts, so a new user missing or forgetting
> it is not a realistic scenario.

If window focus switching is really a rarity, and only done
briefly then I agree that a context manager makes a nice and neat

But it's too powerful a generalisation for such a small corner

Have you considered adding a keyword argument to each of your
global functions, which is normally None, but allows a user to
provide a prefered focus window?

enter_text("test.txt", focus=save_dialog)
press_button(Savebutton, focus=save_dialog)

(Those are just guesses at your API functions; sorry.)

When focus remains None, your usual assumptions about focus would
apply, otherwise the user preference overrides it.

Neil Cerutti

More information about the Python-list mailing list