Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the paging-multilevel-translate.py to work with Python 3 #20

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

modulitos
Copy link

@modulitos modulitos commented Oct 25, 2020

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 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.

@modulitos
Copy link
Author

@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.

@remzi-arpacidusseau
Copy link
Owner

remzi-arpacidusseau commented Nov 18, 2020 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants