Python error in Walking Into It?

I ran into a Python error at the very first prompt: “AttributeError: ‘str’ object has no attribute ‘decode’”. This was on Python 3.6.9 (the built-in python) on Ubuntu 18.04 LTS, running in the terminal. I fixed this by removing the decode() calls on lines 205 and 231, and I was able to complete the rest of the game. This might be an issue specific to Linux, and this change might break things on windows I’m guessing?

Trying to use Python 2 had a different error: “AttributeError: ‘int’ object has no attribute ‘lower’” on line 318 (when deciding who to go first).

2 Likes

Python 3.6 is seriously old. It’s the 2016 release. (3.6.9 is more recent but that’s only bug-fixes.) It is strongly recommended to install the current Python3 through your package manager to run anything real.

(Python 2 is no longer supported at all.)

The missing decode() calls will probably cause some Unicode display problems, nothing worse. If you didn’t notice anything, don’t worry about it.

2 Likes

Ouch. Sorry about this.

I tested this on Python 2 to make sure it worked, and I think what happened was, I noticed a str() function that seemed superfluous with input(), and I deleted it. It wasn’t.

I just tested a hotfix, and the changed file is here, so you can save it locally.

While I’m 99% sure of the fix, I I want to do further checking before submitting anything to the comp itself.

Thanks again for finding this!

1 Like

For what it’s worth, I just tested with python 3.10 and the same error happens as with python 3.6.

The link gets a 404… Anyway, in my case it doesn’t really matter as I’ve already finished the game. The python 3 issue might just be an idiosyncratic issue with my system.

1 Like

I … forgot to make the repository public at the start of IFComp. Ouch! Now that I have, the link appears okay, though the stuff after wii.py can go. I still need to push the update to the main website.

Thanks again for reporting these bugs and finding a way ahead despite these issues. I’d been thinking of some post-comp tweaks to add, and a bug report like this helped me focus on them a bit. It also motivated me to look up some general Python stuff I’d always been curious about but never got around to.

Also crashes for me (OSX Mojave) with Python 3.9, and in a different way with Python 2.7.

Python 3.9:

$ python3.9 wii.py 
First, this game can give short descriptions instead of displaying minimal ASCII art. The ASCII art may cause problems for screen readers.
Would you prefer descriptions instead of ASCII art (F forces descriptions for screen readers)? Y/N/F
Traceback (most recent call last):
  File "/private/tmp/walking-into-it/wii.py", line 994, in <module>
    my_games = GameTracker()
  File "/private/tmp/walking-into-it/wii.py", line 279, in __init__
    show_introductory_text()
  File "/private/tmp/walking-into-it/wii.py", line 205, in show_introductory_text
    raw = raw.decode().lower()
AttributeError: 'str' object has no attribute 'decode'

_find_getch() returns a string, not a bytes object, so you can’t decode it.

Python 2.7:

$ python2.7 wii.py 
Since you seem to be using Python 2, I want to ask you for your preferred terminal width.This only affects text-wrapping for paragraphs of text, so you can just ignore this question if you'd like. 
First, this game can give short descriptions instead of displaying minimal ASCII art. The ASCII art may cause problems for screen readers.
Would you prefer descriptions instead of ASCII art (F forces descriptions for screen readers)? Y/N/F
Note this setting isn't fixed. It can be toggled by typing R.
If you've read the introduction before, you can (S)how the remaining introductory text without pauses (8 chunks left) or (F)ast-forward to ignore the remaining text. You can also push any key to read the next bit, starting now.
  (Skipping the rest of your conversation with Sandy...)
A new game. Who moves first? 1 = you, 2 = Sandy.  1 
Traceback (most recent call last):
  File "wii.py", line 994, in <module>
    my_games = GameTracker()
  File "wii.py", line 280, in __init__
    self.clear_and_restart_game()
  File "wii.py", line 294, in clear_and_restart_game
    self.current_first = self.current_mover = self.choose_sides()
  File "wii.py", line 318, in choose_sides
    format(kids_name, who_now, log_cr())).lower().strip()
AttributeError: 'int' object has no attribute 'lower'

This is because, in Python 2, input() evaluates the input, so ‘1’ becomes the int 1, not the string ‘1’. You need raw_input() to get the string. (This was changed in Python 3.)

1 Like

Thanks to everyone in this topic, and apologies for the confusion/annoyance. Next time I think I’ll document why that str(my_var_thats_probably_a_string) is, in fact, NOT superfluous. The new version is updated now.

3 Likes