1

I ran into some code and was wondering what it does. I was trying to search the site for a similar question but didn't find anything about this specific question.

class Foo:
    def __init__(self, data):
        Foo.latest = self
        self.data = data

What does the .latest statement do?

  • 7
    It accesses the `.latest` attribute on the object `Foo`, just like it would for any object (class objects being just like any other object in Python). Here, it keeps track of the last instance created on the class itself, adding a class attribute `Foo.latest = self` – juanpa.arrivillaga Jan 26 '18 at 21:52
  • Okay, I think I got it now. Thanks! – shahaf hermann Jan 27 '18 at 09:53

0 Answers0