inheriting from long on Python2 or int on Python3
Skip Montanaro
skip.montanaro at gmail.com
Sat Mar 21 17:55:33 EDT 2020
> import sys
>
> class C_hash(int if sys.version_info.major >= 3 else long):
...
There's nothing incorrect with your solution. Chris offered another. I
was going to suggest you consider running your code through 2to3 to
see what it does. I created a C_hash class similar to yours:
class C_hash(long):
def __new__(cls, bits, m, N=1):
obj = super(C_hash, cls).__new__(cls, bits)
obj._m = m
obj._N = N
return obj
def meth(self):
pass
When I ran it through 2to3, it didn't make any transformations, which
I thought odd. Still, assuming I did something wrong, you might poke
around with it a bit to see if you can get it to do the work for you.
Skip
More information about the Python-list
mailing list