This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: 2to3 division problems leading to program crashes in Python3
Type: behavior Stage: resolved
Components: Versions: Python 3.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: xxm, zach.ware
Priority: normal Keywords:

Created on 2019-07-30 03:39 by xxm, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
runGame.py xxm, 2019-07-30 03:39 This is a snake game. Type "python2 snake.py " in command line and it will run normally in Python2. However, the program will crash in Python3 after 2to3.
Messages (2)
msg348712 - (view) Author: Xinmeng Xia (xxm) Date: 2019-07-30 03:39
The snake game will report a crash in Python3:
Traceback (most recent call last):
File "/home/xxm/Desktop/instrument/datasetpy3/Snake_game/runGame.py",line 20, in <module>
        w.addch(food[0], food[1], curses.ACS_PI)
TypeError: integer argument expected, got float

food is assigned at line 19 "food = [sh/2, sw/2]"
addch accepts "int" as the types of the first two parameter. In Python2, it will work well since the results of division will be "int".In Python3  ,the results will be "float"
msg348713 - (view) Author: Zachary Ware (zach.ware) * (Python committer) Date: 2019-07-30 03:56
This is not a bug; division changed in Python 3 such that `/` is the "true division" operator, whereas `//` is the "integer division" operator.

Note that this was actually added in Python 2.2, though it was guarded by `from __future__ import division` for the remainder of the 2.x line.
History
Date User Action Args
2022-04-11 14:59:18adminsetgithub: 81894
2019-07-30 03:56:24zach.waresetstatus: open -> closed

type: crash -> behavior
components: - 2to3 (2.x to 3.x conversion tool)

nosy: + zach.ware
messages: + msg348713
resolution: not a bug
stage: resolved
2019-07-30 03:39:50xxmcreate