Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

The inner function just falls out of scope, and is presumably collected.

  >>> def foo(mylist):
  ...   def n_to_the_n(n):
  ...     if n > 1:
  ...       return n**n
  ...     return 1
  ...   return [n_to_the_n(i) for i in mylist]
  ... 
  >>> print foo([1,2,3,4,5])
  [1, 4, 27, 256, 3125]
  >>> foo
  <function foo at 0x6e5f0>
  >>> n_to_the_n
  Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
  NameError: name 'n_to_the_n' is not defined
  >>>
Note that I only made the inner function longer than necessary for illustrative purposes :-)


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: