Need help with Python scoping rules

Piet van Oostrum piet at cs.uu.nl
Thu Aug 27 16:07:51 EDT 2009


>>>>> kj <no.email at please.post> (k) wrote:

>k> No, the fact() function here represents an internal "helper"
>k> function.  It is meant to be called only once to help initialize
>k> a class variable that would be inconvenient to initialize otherwise;
>k> this helper function is not meant to be called from outside the
>k> class statement.  Granted, in the example I gave, the "helper"
>k> function (factorial) is a bit silly, but that was just intended as
>k> a simple and familiar example of a recursive function.  The actual
>k> function that motivated this post would be considerably more
>k> difficult to explain and would have obscured the point of the post.

Classes don't have helper functions; they have methods. Instance
methods, static methods or class methods. Your's isn't either of these.
Methods are to be called like `something.method(...)'.

-- 
Piet van Oostrum <piet at cs.uu.nl>
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email: piet at vanoostrum.org



More information about the Python-list mailing list