[Tutor] Attribution Error

Alan Thwaits basicbare at gmail.com
Fri Apr 17 18:59:51 EDT 2020


Can you give me an example of  "insert print statements after each
current_scene assignment"?

I know it sounds simple, but I'm a bit at sea with it.

Thanks!

Alan

On Fri, Apr 17, 2020 at 12:30 PM Alan Gauld via Tutor <tutor at python.org>
wrote:

> 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
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>


More information about the Tutor mailing list