36

I'm trying to run the following code with Python 3.7:

import sys
print(sys.maxint)

but I get an error:

D:\Python3.7\python.exe "D:/PyCharm 2017.2.3/Workplace/maximizer.py"
Traceback (most recent call last):
File "D:/PyCharm 2017.2.3/Workplace/maximizer.py", line 2, in <module>
    print(sys.maxint)
AttributeError: module 'sys' has no attribute 'maxint'

How do I fix it?

Georgy
  • 12,464
  • 7
  • 65
  • 73
Trux
  • 403
  • 1
  • 5
  • 12
  • As the error message states, you're trying to access the `maxint` attribute of the `sys` module, but `sys` doesn't have an attribute named `maxint`. Maybe you meant `sys.maxsize`? –  Oct 31 '17 at 03:24

2 Answers2

65

In python3, sys.maxint changed to sys.maxsize.

Here are the values:

Python2

>>> sys.maxint
9223372036854775807

Python3

>>> sys.maxsize
9223372036854775807

On the same platform, the values match. The value is typically 2**31 - 1 on a 32-bit platform and 2**63 - 1 on a 64-bit platform.

Replacing your call to maxint with maxsize will stop this particular Traceback.

JacobIRR
  • 8,545
  • 8
  • 39
  • 68
  • Integer.MAX_INTEGER changed to sys.maxint. Then it changed to sys.maxsize. I am wondering what's next?? – kta Aug 11 '20 at 02:51
1

You are running your code using python3, which does not have a sys.maxint. Python2, however, does. So run your code as

python2 "D:/PyCharm 2017.2.3/Workplace/maximizer.py"
John Anderson
  • 35,991
  • 4
  • 13
  • 36