class attrdict

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Hallvard B Furuseth

    #16
    Re: class attrdict

    Alex Martelli writes:
    (...)
    >class Namespace(objec t):
    (...)
    I might, if it weren't for the redundant "if" and the horribly buggy
    interference between separate instances -- which is why I wrote it,
    almost six years ago and without the bugs, as
    <http://aspn.activestat e.com/ASPN/Python/Cookbook/Recipe/52308.
    Nice one. I gotta dig up the Cookbook again.

    --
    Hallvard

    Comment

    • Hallvard B Furuseth

      #17
      Re: class attrdict

      Alex Martelli writes:
      You make a good point. I do like being able to say foo.bar=baz rather
      than foo['bar']=baz in certain cases -- not so much to save 3 chars, but
      to avoid excessive punctuation; however, I don't really need this AND
      all of dict's power at the same time, so, I don't inherit from dict:-).
      Yes. Attribute syntax looks nicer, in particular one implements a sort
      of private "variables collected in a dict" thing (e.g. SQL field names)
      but still wants some dict functionality.

      Another variant I thought of would be to prefix dict methods with '_'
      (except those that already start with '__') and (if implemented as a
      dict subtype) also override the original names with a "sorry, use
      _<foo>" error method.

      (Posting a bit sporatically currently, disappearing for a week again
      now.)

      --
      Hallvard

      Comment

      Working...