On Thursday, June 5, 2014 2:50:22 PM UTC-7, Dinakar Muthiah wrote:
>
> Partition.i_part = i_part
>
> Then if later I wrote:
>
> p = Partition([3,2,1])
>
> I can call 
>
> p.i_part(2)
>

That works. Of course, without the "monkey-patching" (changing code on a 
class after its original definition), you could also just write

i_part(p,2)

which is the same number of characters and works without modifying global 
objects that may be used elsewhere. The great thing about python is that 
you don't have to be hung up on implementing everything as a method. Often, 
plain old functions are a much cleaner and more concise way of expressing 
your computations.

Of course, as pointed out, if you think the functionality warrants wider 
adoption, you should create a ticket and provide a code change proposal. 
For incorporation into sage proper, the function would almost certainly 
needs to be placed as a method somewhere, to get it out of the way of 
naming conflicts. For your own code projects you probably don't have to 
bother.

-- 
You received this message because you are subscribed to the Google Groups 
"sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/d/optout.

Reply via email to