latter is supposed to simply call the formeri os popen('dir / py' __next__('helloshell py\ni os popen('dir / py'next(itypeerror_wrap_close object is not an iterator the reason for this is subtle--direct __next__ calls are intercepted by __getattr__ defined in the pipe wrapper objectand are properly delegated to the wrapped objectbut next function calls invoke python' operator overloading machinerywhich in bypasses the wrapper' __getattr__ for special method names like __next__ since the pipe wrapper object doesn' define __next__ of its ownthe call is not caught and delegatedand the next built-in fails as explained in full in the book learning pythonthe wrapper' __getattr__ isn' tried because begins such searches at the classnot the instance this behavior may or may not have been anticipatedand you don' need to care if you iterate over pipe lines automatically with for loopscomprehensionsand other tools to code manual iterations robustlythoughbe sure to call the iter built-in first--this invokes the __iter__ defined in the pipe wrapper object itselfto correctly support both flavors of advancementi os popen('dir / py' iter(ii __next__('helloshell py\nnext( 'more py\ system tools what for loops do now both forms work