Function to apply superset of arguments to a function
Mel
mwilson at the-wire.com
Wed Sep 9 17:03:55 EDT 2009
David Stanek wrote:
> On Wed, Sep 9, 2009 at 12:45 PM, Andrey Fedorov<anfedorov at gmail.com>
> wrote:
>> I've written a function [1] called apply_some which takes a set of
>> keywords arguments, filters only those a function is expecting, and
>> calls the function with only those arguments. This is meant to
>> suppress TypeErrors - [ ... ]
> What is your use-case for using this? It seems really odd to me.
I may have run into one possible use. I have a program that uses DB-API 2.0
to work with a database, sometimes SQLite3, sometimes PostgreSQL. Connect
parameters are built up in a dict from a combination of defaults,
environment values, and command-line arguments. This dictionary has to be
pruned down before calling connect, because sqlite3.connect doesn't take the
wide assortment of arguments that are needed for PostgreSQL. The existing
program does this "by hand", being programmed in advance to know which
parameters are acceptable to which database module.
Mel.
More information about the Python-list
mailing list