On Oct 11, 12:57*pm, Eloff <dan.el...@gmail.comwrote:
In the _ast module Attribute, Subscript, Name, List, Tuple all have an
expr_context associated with them which is defined as:
expr_context = Load | Store | Del | AugLoad | AugStore | Param
I have no idea what they mean, and what's the difference between them.
I'm porting _ast to IronPython and this is the only part I've had
difficulty understanding. The only clue I've found is that all these
expressions are unique in that they can occur in assignment context.
Any insights at all?
They refer to how the expression is used in its context. You can cross
AugLoad and AugStore off because they are not used by the current
implementation. I hope this code examples will explain the rest:
Load:
a = 2
Module(body=[Assign(targets=[Name(id='a', ctx=Store())],
value=Num(n=2))])
Store:
print a
Module(body=[Print(dest=None, values=[Name(id='a', ctx=Load())],
nl=True)])
Del:
del a
Module(body=[Delete(targets=[Name(id='a', ctx=Del())])])
Param:
def f(a): pass
Module(body=[FunctionDef(name='f', args=arguments(args=[Name(id='a',
ctx=Param())], vararg=None, kwarg=None, defaults=[]), body=[Pass()],
decorator_list=[])])
I hope that helps!
>
Thanks,
-Dan