[Tutor] Attribution Error

Mats Wichmann mats at wichmann.us
Fri Apr 17 12:24:45 EDT 2020


On 4/17/20 7:25 AM, Alan Thwaits wrote:
> I can't resolve an attribution error message in the script for my first
> text-based rooms-and-choices game. After reading everything I could find
> about it online, I'm still banging my head in frustration.  Any help,
> direction, or suggestions would be greatly appreciated.
> 
> The error message I get is this:
> 
> Traceback (most recent call last):
>   File "C:\Users\Alan\Documents\Python\ex45.py", line 350, in <module>
>     a_game.play()
>   File "C:\Users\Alan\Documents\Python\ex45.py", line 59, in play
>     next_scene_name = current_scene.enter()
> AttributeError: 'NoneType' object has no attribute 'enter'

Once you get used to it, this error message is quite straightforward,
although in the beginning it is a little daunting.  It means:

you tried to access an attribute of an object, but the object doesn't
have that attribute. Per the error message, the object is actually the
special object None, which has no attributes.

you have an unexpected value, and need to add some form of error handling.

>         current_scene = self.scene_map.opening_scene()
>         last_scene = self.scene_map.next_scene('finished')
> 
>         while current_scene != last_scene:
>             next_scene_name = current_scene.enter()          << line 59
>             current_scene = self.scene_map.next_scene(next_scene_name)

so one of these two calls, "scene_map_opening_scene()" or inside the
loop "scene_map_next_scene()" has returned None instead of a valid scene
instance.




More information about the Tutor mailing list