osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

The "loop and a half"


On Thu, 5 Oct 2017 10:15 am, Thomas Jollans wrote:

> If you apply that kind of thinking consistently with Python you'll get
> caught in an infinite loop trying to explain attribute access before
> even teaching print().
> 
> To call print, you need to access print.__call_. To access that
> attribute, you need to check print.__dict__ (and some other things),
> which is itself an attribute of print. To access that, (...)
> 
>>>> print.__class__.__dict__['__call__'].__call__(print, "hello world")
> hello world


Its worse than that. Conceptually, you are calling type(print).__call__, not
print.__call__. But how do you call type? With type.__call__(print), except
that it is actually type(type).__call__(type, print) which is recursive...

Obviously the real interpreter doesn't do that. Doing attribute access on the
type is magic, and built into the interpreter: there's no infinite regress.


> "simple and constituent parts" is, quite often, not well-defined.

Indeed.


> Iterators are pretty simple, and, while they have constituent parts,
> pretty fundamental to Python, at least in spirit.

But you don't need to know the slightest thing about iterators in order to
learn how to iterate over lists, strings, tuples, dicts etc. In fact,
iterators are merely a subset of a more fundamental "kind" of object,
iterables: anything which can be iterated over.



-- 
Steve
?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure
enough, things got worse.