dynamic attribute syntax

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

    dynamic attribute syntax

    Hi all,
    Thinking of a syntax for 'getattr' and 'setattr' dynamic access.

    'obj.prop' has an easy access, but

    att= 'prop'
    getattr( obj, att )

    is much clumsier, while no less useful, maybe more.

    What are the changes, pros and cons, involved in something like:

    obj:att for a dynamic access, and obj.att for static?

    Snice readability is a factor, I'm open to other markings than ':'.
    '$' and '?' are available, and I note that a~b, a:b, and, a!b for
    identifiers 'a' and 'b' are unambiguous.

  • Paul Boddie

    #2
    Re: dynamic attribute syntax

    On 17 Aug, 21:29, castironpi <castiro...@gma il.comwrote:
    >
    What are the changes, pros and cons, involved in something like:
    >
    obj:att for a dynamic access, and obj.att for static?
    A previous proposal and discussion can be found here:

    Dynamic attribute access is currently possible using the “getattr” and “setattr” builtins. The present PEP suggests a new syntax to make such access easier, allowing the coder for example to write:


    Paul

    Comment

    • castironpi

      #3
      Re: dynamic attribute syntax

      On Aug 17, 2:46 pm, Paul Boddie <p...@boddie.or g.ukwrote:
      On 17 Aug, 21:29, castironpi <castiro...@gma il.comwrote:
      >
      >
      >
      What are the changes, pros and cons, involved in something like:
      >
      obj:att for a dynamic access, and obj.att for static?
      >
      A previous proposal and discussion can be found here:
      >
      Dynamic attribute access is currently possible using the “getattr” and “setattr” builtins. The present PEP suggests a new syntax to make such access easier, allowing the coder for example to write:

      >
      Paul
      Thanks for the reference. Well, check out the two alternatives, a~b
      and a!b, which are easy on the eyes, and weren't proposed, but don't
      allow expressions. (Turns out 'if a:b' is valid, so never mind that
      one.) I also won't let you forget that $ and ? are unused so far
      too. I see syntax was one of the complaints.

      Comment

      • Fredrik Lundh

        #4
        Re: dynamic attribute syntax

        castironpi wrote:
        'obj.prop' has an easy access, but
        >
        att= 'prop'
        getattr( obj, att )
        >
        is much clumsier, while no less useful, maybe more.
        maybe more? ok, you *are* utterly and completely unable to post
        anything that makes any sense at all to anyone that uses Python.
        plonkeliplonk.

        Comment

        • castironpi

          #5
          Re: dynamic attribute syntax

          On Aug 17, 3:05 pm, Fredrik Lundh <fred...@python ware.comwrote:
          castironpi wrote:
          'obj.prop' has an easy access, but
          >
          att= 'prop'
          getattr( obj, att )
          >
          is much clumsier, while no less useful, maybe more.
          >
          maybe more?  ok, you *are* utterly and completely unable to post
          anything that makes any sense at all to anyone that uses Python.
          plonkeliplonk.
          More constructive contributions on both sides there. Good one.

          Comment

          Working...