Latest recipes tagged "int"http://code.activestate.com/recipes/tags/int/new/2011-04-06T14:52:06-07:00ActiveState Code RecipesRoman numeral class with overloaded int methods (Python)
2011-04-06T14:52:06-07:00thom nealehttp://code.activestate.com/recipes/users/4176069/http://code.activestate.com/recipes/577640-roman-numeral-class-with-overloaded-int-methods/
<p style="color: grey">
Python
recipe 577640
by <a href="/recipes/users/4176069/">thom neale</a>
(<a href="/recipes/tags/homework/">homework</a>, <a href="/recipes/tags/int/">int</a>, <a href="/recipes/tags/overloading/">overloading</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/roman/">roman</a>).
</p>
<p>This Roman class is a subclass of int and supports the same methods int does, but any special methods that would normally return ints are return a new instance of Roman. You can use instances of this class in math expressions and a Roman instance will be returned, for example. </p>
<p>The class decorator used to achieve this was suggested by Alex Martelli '<a href="http://stackoverflow.com/questions/1242589/subclassing-int-to-attain-a-hex-representation/1243045#1243045">here</a> on stackoverlow.com.</p>