Open modulitos opened 4 years ago
@remzi-arpacidusseau Can we merge this in? I think it will save future students the trouble of having to fix this script when they're running on Python 3.
I can confirm that it introduces no behavioral change.
Will do, thanks!
On Sun, Oct 25, 2020 at 4:35 AM Lucas Swart notifications@github.com wrote:
When running this script with python 3, we get the following error:
❯ python3 paging-multilevel-translate.py ARG seed 0 ARG allocated 64 ARG num 10
Traceback (most recent call last): File "paging-multilevel-translate.py", line 241, in os = OS() File "paging-multilevel-translate.py", line 57, in init for i in range(0, self.maxPageCount): TypeError: 'float' object cannot be interpreted as an integer
This is due to a breaking change in Python 3, where the division operator represents true division, producing a floating point result. Whereas in Python 2, it performs classic division that rounds the result down toward negative infinity (also known as taking the floor).
This PR changes the operator to use //, which according to the docs:
https://www.python.org/dev/peps/pep-0238/
The // operator will be available to request floor division unambiguously.
This should make the script Python 2 and 3 compatible.
You can view, comment on, or merge this pull request online at:
https://github.com/remzi-arpacidusseau/ostep-homework/pull/20 Commit Summary
- python3 fixes
File Changes
- M vm-smalltables/paging-multilevel-translate.py https://github.com/remzi-arpacidusseau/ostep-homework/pull/20/files#diff-7cce49f4a28d56d349eb8b340a17d44a6756e411d591126a8e88d1ed0e82228c (4)
Patch Links:
- https://github.com/remzi-arpacidusseau/ostep-homework/pull/20.patch
- https://github.com/remzi-arpacidusseau/ostep-homework/pull/20.diff
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/remzi-arpacidusseau/ostep-homework/pull/20, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADDKP56DNGLBOJ32ZMFBK7LSMPWPZANCNFSM4S6GT7KA .
When running this script with python 3, we get the following error:
This is due to a breaking change in Python 3, where the division operator represents true division, producing a floating point result. Whereas in Python 2, it performs classic division that rounds the result down toward negative infinity (also known as taking the floor).
This PR changes the operator to use
//
, which according to the docs:https://www.python.org/dev/peps/pep-0238/
This should make the script Python 3 compatible, without changing any behavior in Python 2.
I tested this change by running the script in Python 2, and confirming that the output is the same before and after this change.