exec "x = 3; print x" in a - How does it work?
Veek. M
vek.m1234 at gmail.com
Wed Mar 9 01:21:50 EST 2016
Ben Finney wrote:
> "Veek. M" <vek.m1234 at gmail.com> writes:
>
>> What is the return value of `exec`?
>
> You can refer to the documentation for questions like that.
> <URL:https://docs.python.org/3/library/functions.html#exec>
>
>> Would that object be then used to iterate the sequence in 'a'?
>
> The ‘for’ or ‘while’ statements are correct for iteration.
>
>> I'm reading this:
>> https://www.python.org/download/releases/2.2.3/descrintro/
>
> Why?
>
Well, i had a question on MRO and asked on freenode #python and they
suggested i read that.
My question was:
class A(x, y, z):
pass
class x(q,w,r)
pass
I wanted to know how the __mro__ would be generated (c3 linearization)
I had assumed when using super() it would do:
x, q, w, r, y, z, object
basically hit a base class and finish with all it's parents before
stepping to the next sibling
But then i read somewhere else that it's like this:
x, y, z, q, w, r, object
and of course if q has base-classes then:
x, y, z, q, w, r, e, f, g
which is utterly confusing because you can't tell by looking where e, f,
g are coming from (q) in this case..
This doc:
https://rhettinger.wordpress.com/2011/05/26/super-considered-super/
I was getting all cross-eyed reading this:
'The ancestor tree for our new class is: LoggingOD, LoggingDict,
OrderedDict, dict, object. For our purposes, the important result is
that OrderedDict was inserted after LoggingDict and before dict! This
means that the super() call in LoggingDict.__setitem__ now dispatches
the key/value update to OrderedDict instead of dict.'
I was wondering why they had chosen this notation over the other.
And if you're wondering why that paper - because i was reading Beazley
super() pg 120 and the whole hard-coding avoided using super() bit.
More information about the Python-list
mailing list