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

Is it possible to not return anything from a function in python?

Functions always return something (at least None, when no return-statement was reached during execution and the end of the function is reached). Another case is when they are interrupted by exceptions. In this case exception handling will “dominate over the stack” and you will return to the appropriate except or get some nasty error 🙂 … 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