How can I add a method to the int class?
Add a method to the int class
Collapse
This topic is closed.
X
X
-
barberomarcelo@gmail.comTags: None -
placid
Re: Add a method to the int class
barberomarcelo@ gmail.com wrote:sub class itHow can I add a method to the int class?
2>>class MyInt(int):
>> def times(self,mult iple):
>> return self * multiple
>>>
>> a = 2
>> print a4>> a = MyInt(2)
>> print a
>> 2
>> print a.times(2)
--Cheers
-
Terry Reedy
Re: Add a method to the int class
<barberomarcelo @gmail.comwrote in message
news:1152505455 .432235.275880@ h48g2000cwc.goo glegroups.com.. .You can't. The closest is to subclass int and add your method.How can I add a method to the int class?
Comment
Comment