[Tutor] Proper way to use **kwargs?

Hugo Arts hugo.yoshi at gmail.com
Mon Mar 15 14:40:33 CET 2010


On Mon, Mar 15, 2010 at 1:38 PM, Karjer Jdfjdf <karper12345 at yahoo.com>wrote:

>
> I have 2 questions about this code:
>
> 1. Can I use this in Python 3 ?  I'm not sure if I can use **kwargs in
> Python 3 because it uses the "apply" builtin (if I understand it correctly)
>
> "At this writing, both apply and the special call syntax described in this
> section can be used freely in Python 2.5, but it seems likely that apply
> may go away in Python 3.0. If you wish to future-proof your code, use
> the equivalent special call syntax, not apply."
>
>
what they're saying is that in python 3, the apply function doesn't exist
anymore, so if you want equivalent functionality, you'll have to use special
call syntax. In other words, what you're doing is just fine.



> 2. Are there better ways to achieve what I want to do?
>
>
I'd consider making sure there are no nonsense arguments passed into the
function:

for key in kwargs:
    if key not in options:
       raise ArgumentError("invalid argument: %s" % key)

other than that, looks fine to me

Hugo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100315/b530751e/attachment.html>


More information about the Tutor mailing list