Python 2.5 long

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Ephexeve
    New Member
    • May 2011
    • 20

    Python 2.5 long

    I have this bit of code, which I copied from my book;
    Code:
    def checkIndex(key):
        if not isinstance(key,(int, long)): raise TypeError
        if key < 0: raise IndexError
    But I am currently using Python 3.1, does anyone knows what long is in Python3? Because I am getting an error saying long is not defined, and when I try in Python 2 it works
  • dwblas
    Recognized Expert Contributor
    • May 2008
    • 626

    #2
    Python integers don't have a length, so use int only. If you have huge numbers, then use the decimal class which can handle both extremely small and extremely large numbers. Try this snippet as a test:
    Code:
    x_int = int("123")
    print len(x_int)

    Comment

    • bvdet
      Recognized Expert Specialist
      • Oct 2006
      • 2851

      #3
      int and long are unified as int in Python 3.X. See PEP 237.

      Comment

      • Ephexeve
        New Member
        • May 2011
        • 20

        #4
        Cool, thanks for the help dudes, that helped!

        Comment

        Working...