[Tutor] Attribution Error

Alan Gauld alan.gauld at yahoo.co.uk
Fri Apr 17 12:29:53 EDT 2020


On 17/04/2020 14:25, Alan Thwaits wrote:

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

Note that is says that NoneType has no attribute enter so it is telling
you that, at some point, current_scene is being set to None.
So you need to find that point and either fix it or detect it.

The simplest way is simply to insert print statements after each
current_scene assignment.

If you are familiar with debuggers such as those in eclipse or
VS Code you can set a watch or conditional breakpoint instead.
But a print is usually easiest! Just remember to take them all
out again when done.

> class Engine(object):
>     def play(self):
>         current_scene = self.scene_map.opening_scene()
          print("Current scene: ", current_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)

              print("Current scene: ", current_scene)

My suspicion is that you are somehow encountering an error  in the
next_scene code, or simply running off the end of the scene map...

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




More information about the Tutor mailing list