Is this a closure?
Chris Rebert
cvrebert+clp at gmail.com
Sun Aug 31 20:00:21 EDT 2008
Yes, printReviews() is a closure. In particular, it's closing over the
variable "self", which it's getting lexically from printSelf().
- Chris
On Sun, Aug 31, 2008 at 4:53 PM, ssecorp <circularfunc at gmail.com> wrote:
> A method on a class:
>
> def printSelf(self):
> def printReviews():
> for review in self.reviews:
> review.printSelf()
> print "Idnbr: ", self.idnumber, "Reviews: ", printReviews()
>
> I don't have to pass an argument to printReviews because everything
> defined inside printSelf is aware of outer variables? Or is that
> wrong? If it is right, is this what a closure means?
>
> Because Python is lexically scoped right? Is lexical scope+closures =
> organized dynamic scope kind of if you get my point?
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
--
Follow the path of the Iguana...
http://rebertia.com
More information about the Python-list
mailing list