News for hackers. Stuff that matters.
Re:Understanding python *args and **kwargs by jeff18 on Friday October 02, 2009 @01:52PM (#857567)

  def test(a, b, *args, **kwargs):
    print a, b, args, kwargs

  >>> test(1, 2, 3, 4, aa=5, bb=6)
  1 2 (3, 4) {'aa': 5, 'bb': 6}
'nuff said
Re:Understanding python *args and **kwargs by TommyWiseau on Friday October 02, 2009 @11:47AM (#857285)
Jesus, does this really require such a long article? Just open the interpreter and check it out. Took me 5 minutes when I decided to figure it out.
Re:Understanding python *args and **kwargs by plinkplonk on Friday October 02, 2009 @01:00PM (#857445)
The number of upvotes such a content-lite article gets on HN is interesting, and maybe an indicator of a changing demographic here.

What's next? a few pages on Ruby's method_missing? :-)

Re:Understanding python *args and **kwargs by algorias on Friday October 02, 2009 @12:39PM (#857389)
5 minutes followed by a sweet aha! moment.

What the article seems to miss, though (only skimmed it), is that you need to be incredibly careful with taking kwargs, specially if you're passing them along into secondary functions within the called function. Hidden bugs lie that way, as you could end up with bad/misspelled args that you think are having an effect, but aren't.

Always make sure all kwargs get unpacked.

Re:Understanding python *args and **kwargs by ubernostrum on Friday October 02, 2009 @12:52PM (#857422)
It's also covered in the official Python tutorial.
Re:Understanding python *args and **kwargs by drawkbox on Friday October 02, 2009 @03:37PM (#857828)
No kidding.

  A much, much more simple way to put it is 
  anything *args is a list, anything  **kwargs is 
  a dictionary.

  The * simply means list (set). 
  ** simply means dictionary (name/value pairs)

  * and ** has a much different meaning in other 
  languages as parameters.

  * args is very similar to ... in other languages 
  that let you send n arguments.
Re:Understanding python *args and **kwargs by DannoHung on Friday October 02, 2009 @11:20AM (#857208)
I've noticed quite a bit of introductory level Python stuff showing up on HN lately, and while there's nothing wrong with that (and I appreciated the link to the Decorator PEP because I'd forgotten about the decorator generator 3rd party module), I wonder what's driving it.
Re:Understanding python *args and **kwargs by chasingsparks on Friday October 02, 2009 @04:02PM (#857888)
Google? Honestly, I just took what I assumed was going to be a plunge back into Python for web development (preferred lang is Ruby). I opted to relearn Python because Google has a visible preference for it. After a 24 hour refresher (reading Guido's documentation), I am pleasantly surprised. Who knew Python actually has some strong things going for it? ;)
Re:Understanding python *args and **kwargs by garnet7 on Friday October 02, 2009 @10:35PM (#858424)
> I wonder what's driving it.

Just some guesses/thinking-out-loud:

* people are getting sick of php (well, sicker than usual)

* Python 3 has been out for a while and it's starting to be used by more people

* Perl 6 is seeing regular releases, some tutorial material is showing up out there, so maybe it's having an effect of getting people interested in new languages

* It's possible that some Rubyists who left the ship are now returning.

Re:Understanding python *args and **kwargs by juvenn on Friday October 02, 2009 @12:08PM (#857326)
Because there're unqualified hackers here.
Re:Understanding python *args and **kwargs by scott_s on Friday October 02, 2009 @02:31PM (#857660)
I was unfamiliar with args and kwargs in Python, despite using the language for lots of scripting, and liking the language immensely. It's a simple concept and now I get it, but I'm still unclear on what star and starstar mean, which is something I keep meaning to look up.

Does that make me an unqualified hacker?

Re:Understanding python *args and **kwargs by mattyb on Friday October 02, 2009 @08:16PM (#858289)
Re:Understanding python *args and **kwargs by randallsquared on Friday October 02, 2009 @03:17PM (#857777)
Interesting that "unqualified hackers" can be read in two ways, both of which are true for the statement. Or maybe just interesting to me. :)