Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news-1.dfn.de!news.dfn.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Neil Cerutti Newsgroups: comp.lang.python Subject: Re: Help me pick an API design (OO vs functional) Date: 26 Mar 2013 14:13:30 GMT Organization: Norwich University Lines: 28 Message-ID: References: <68da956e-ebe0-4f58-92cd-f7ffff0075b4@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: individual.net V49OArhL9qYlNxS6kjVKnAp9EvDwYaatUbZ9LfZ6AGT17Jk1e0 Cancel-Lock: sha1:PDWVIMnKixtwmsbRSwIVpmLBorU= User-Agent: slrn/0.9.9p1/mm/ao (Win32) Xref: csiph.com comp.lang.python:41903 On 2013-03-25, Mitya Sirenef 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 solution. But it's too powerful a generalisation for such a small corner case. 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