Normalizing arguments

Chris Rebert clp at rebertia.com
Fri Oct 17 13:17:30 EDT 2008


On Fri, Oct 17, 2008 at 8:37 AM, Dan Ellis <dan at remember.this.name> wrote:
> Given some function, f(a, b, c=3), what would be the best way to go
> about writing a function, g(f, *args, **kwargs), that would return a
> normalized tuple of arguments that f would receive when calling
> f(*args, **kwargs)? By normalized, I mean that the result would always
> be (a, b, c) regardless of how g was called, taking into account
> positional arguments, keyword arguments, and f's default arguments.
>
> g(f, 1, 2, 3) -> (1, 2, 3)
> g(f, 1, 2, c=3) -> (1, 2, 3)
> g(f, 1, c=3, b=2) -> (1, 2, 3)
> g(c=3, a=1, b=2) -> (1, 2, 3)
> g(1, 2) -> (1, 2, 3)
>
> All the required information is available between args, kwargs and f
> (the function object), but I don't know the exact algorithm. Has
> anyone already done this, or should I just dig around in the CPython
> source and extract an algorithm from there?
> --
> http://mail.python.org/mailman/listinfo/python-list
>

Why do you want/need this magical g() function considering that, as
you yourself point out, Python already performs this normalization for
you?

Cheers,
Chris
-- 
Follow the path of the Iguana...
http://rebertia.com



More information about the Python-list mailing list