Loading ...
Sorry, an error occurred while loading the content.

72Re: [python-iter] Colon syntax: We barely knew thee...

Expand Messages
  • gzeljko
    Mar 3, 2001
      From: <qrczak@...>
      >
      > 1. xkeys(), xitems().
      > 2. keys, items.
      > 3. keys(), items().
      >
      >
      > Why 1: Doesn't change existing methods or break any existing code.
      > Doesn't require any magic to work - easy to understand.
      > Consistent with xrange() and xreadlines().
      >
      > Why not 1: Introduces an unnecessary duplication of names only to
      > enable good performance. A programmer should not have to
      > worry whether he should use keys or xkeys, because their
      > meaning is essentially the same.
      >
      >
      > Why 2: A single attribute can be used as either iterator or list
      > producer, with backward-compatible syntax for the latter.
      >
      > Why not 2: Attribute syntax plays the role of a method only because of
      > backward compatibility. Classes must implement this using
      > __getattr__ because it's really a stateful method call.
      > Doesn't scale to places when an argument is needed or to
      > module-scope functions (e.g. range).
      >

      You can think about that in your own terms :)

      so:

      dict.keys = stateless lazy list
      dict.keys() = dict.keys.__call__() - to produce old fashion list

      __getattr__-don't-needed-ly-y'rs-gzeljko
    • Show all 27 messages in this topic