What do _ast Load | Store | Del | AugLoad | AugStore | Param mean?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Eloff

    #1

    What do _ast Load | Store | Del | AugLoad | AugStore | Param mean?

    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?

    Thanks,
    -Dan
  • Benjamin

    #2
    Re: What do _ast Load | Store | Del | AugLoad | AugStore | Parammean?

    On Oct 11, 12:57 pm, Eloff <dan.el...@gmai l.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(nam e='f', args=arguments( args=[Name(id='a',
    ctx=Param())], vararg=None, kwarg=None, defaults=[]), body=[Pass()],
    decorator_list=[])])

    I hope that helps!
    >
    Thanks,
    -Dan

    Comment

    • Eloff

      #3
      Re: What do _ast Load | Store | Del | AugLoad | AugStore | Parammean?

      On Oct 11, 9:22 pm, Benjamin <musiccomposit. ..@gmail.comwro te:
      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(nam e='f', args=arguments( args=[Name(id='a',
      ctx=Param())], vararg=None, kwarg=None, defaults=[]), body=[Pass()],
      decorator_list=[])])
      >
      I hope that helps!
      >
      Very much! Thank you for such a clear explanation!

      Cheers,
      -Dan



      Comment

      Working...