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

Python 2. #5

Open
taitep opened this issue Sep 5, 2023 · 3 comments
Open

Python 2. #5

taitep opened this issue Sep 5, 2023 · 3 comments

Comments

@taitep
Copy link

taitep commented Sep 5, 2023

Python 2 should not be used. Period. Fix: Convert all code. @ternus

@DonMiller9294
Copy link

Are you asking how to convert your code to python 3?

@taitep
Copy link
Author

taitep commented Sep 12, 2023

no, i just do not think i could convert all code of the repo.

@rFurgan
Copy link

rFurgan commented Nov 16, 2024

There isn't much to do in order to make the codes compatible in Python 3.x

In snake.py and snake2.py the only thing that's causing issues is GRID_WIDTH and GRID_HEIGHT being interpreted as float. This causes issues with the randint function call as it expects two integers as input.

To fix this cast the value to int:

GRID_WIDTH = int(SCREEN_WIDTH / GRIDSIZE)
GRID_HEIGHT = int(SCREEN_HEIGHT / GRIDSIZE)

As for lunarlander.py there are some small issues in the load_image function. The first issue being the way exceptions are handled along with the print of that error message.

So you'd have to change

    except pygame.error, message:
        print 'Cannot load image:', fullname
        raise SystemExit(message)

to

    # Catch the exception and assign it to the "error" variable
    except pygame.error as error:

        # Here you just need the parenthesis
        print('Cannot load image: ', fullname)

        # Throw the exception with the error message
        raise SystemExit(error)

The second one is more of a warning because the colorkey in the load_image function is compared to -1 with is instead of ==. If you're curious on what the difference is, check this out

So you'd have to change

if colorkey is -1:

to

if colorkey == -1:

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

No branches or pull requests

3 participants