In my functions, I check for the types of the input so that it is valid (example - for a function that checks the primality of 'n', I don't want 'n' to be inputted as a string).
The problem occurs with checking for longs and ints.
In Python 3.3, they removed the long-type number, so the problem occurs with this:
def isPrime(n):
"""Checks if 'n' is prime"""
if not isinstance(n, int): raise TypeError('n must be int')
# rest of code
This works universally for both v2.7 and v3.3.
However, if I import this function in a Python 2.7 program, and enter a long-type number for 'n', like this: isPrime(123456789000), it would obviously raise a TypeError because 'n' is of the type long, not int.
So, how can I check if it is valid input for both v2.7 and v3.3 for longs and ints?
Thanks!
isPrime(123456789000L)?isPrime(123456789000L)andisPrime(123456789000)are essentially the same thing:isinstance(123456789000L, int)andisinstance(123456789000, int)both returnFalse.isinstance(123456789000, int)returnsTruefor me on both Python 2.6 and Python 2.7.