After `x = x.y()`, why did `x` become `None` instead of being modified (possibly causing “AttributeError: ‘NoneType’ object has no attribute”)?

Summary The method in question returns the special value None, which is the unique instance of the NoneType type. It updates the object as a side effect, and does not return that object. Since x.y() returns None, x = x.y() causes x to become None, and x.y().z() fails because None does not have the specified … Read more

What causes `None` results from BeautifulSoup functions? How can I avoid “AttributeError: ‘NoneType’ object has no attribute…” with BeautifulSoup?

Overview In general, there are two kinds of queries offered by BeautifulSoup: ones that look for a single specific element (tag, attribute, text etc.), and those which look for each element that meets the requirements. For the latter group – the ones like .find_all that can give multiple results – the return value will be … Read more

Python attributeError on __del__

Your __del__ method assumes that the class is still present by the time it is called. This assumption is incorrect. Groupclass has already been cleared when your Python program exits and is now set to None. Test if the global reference to the class still exists first: def __del__(self): if Groupclass: Groupclass.count -= 1 or … Read more

Why is Tkinter widget stored as None? (AttributeError: ‘NoneType’ object …)(TypeError: ‘NoneType’ object …) [duplicate]

widget is stored as None because geometry manager methods grid, pack, place return None, and thus they should be called on a separate line than the line that creates an instance of the widget as in: widget = … widget.grid(..) or: widget = … widget.pack(..) or: widget = … widget.place(..) And for the 2nd code … Read more