"John Nagle" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] | [EMAIL PROTECTED] wrote: | > I wanted to know if there's any way to create a method that takes a | > default parameter, and that parameter's default value is the return | > value of another method of the same class. For example: | > | ... | | > | > def meth2(self, arg=meth1()): | | Not good. If the default value of an argument is mutable, there | are wierd effects, because the default value is bound once when the | class is created, then shared between all later uses. This is almost | never what was wanted or intended, and it's a common source of subtle | bugs. | | In general, default values should be immutable constants only.
Then one would have to restrict default args to immutable builtins. There is no way to determine (without reading code) whether instances of a user-defined class are mutable or not. tjr -- http://mail.python.org/mailman/listinfo/python-list