News for hackers. Stuff that matters.
Re:Python: Common Newbie Mistakes, Part 1 by mjhea0 on Saturday July 06, 2013 @06:21PM (#6000275)
you could also use a generator function -

    def foo(num=[0]):
        num[0] = num[0] + 1
        return num[0]
Re:Python: Common Newbie Mistakes, Part 1 by tome on Saturday July 06, 2013 @06:27PM (#6000295)
Huh? How's that a generator function?
Re:Python: Common Newbie Mistakes, Part 1 by wahnfrieden on Saturday July 06, 2013 @06:35PM (#6000309)
It's not a generator, but his intention is clear - mutable keyword arguments allow for some clever tricks.
Re:Python: Common Newbie Mistakes, Part 1 by jzwinck on Saturday July 06, 2013 @10:41PM (#6000837)
They sure do--that's why we shouldn't have them. Instead:

  class Foo:
      def __init__(self):
          self.n = 0

      def __call__(self):
          self.n += 1
          return self.n

  foo = Foo()