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

Re: [Cheetahtemplate-discuss] NameMapper placeholder resolution

Expand Messages
  • Edmund Lian
    ... dictionary key. ... Perhaps this code snippet and the name resolution priority [assigned attributes methods computed attributes computed dictionary
    Message 1 of 6 , Sep 11, 2002
      On 09/11/2002 05:12:35 PM Mike wrote:

      >valueForKey looks for an attribute first (using getattr), then a
      dictionary key.
      >So it really boils down to whatever getattr returns. Your experiment
      >shows it prefers attributes over methods. My experiment shows the same
      >thing:
      >
      >ass MyObject:
      >... def __init__(self):
      >... self.apple = 'assigned attribute'
      >... def __getitem__(self, name):
      >... if name == 'apple':
      >... return 'dictionary item'
      >... def __getattr__(self, name):
      >... if name == 'apple':
      >... return 'computed attribute'
      >... def apple(self):
      >... return 'method'
      >...
      >>>> o = MyObject()
      >>>> getattr(o, 'apple')
      >'assigned attribute'
      >
      >This makes sense since instance attributes are stored in the instance's
      >__dict__, while methods are actually part of the class. Python's
      >looker-upper looks first in the instance, then in the class, then in
      >the base classes.

      Perhaps this code snippet and the name resolution priority [assigned
      attributes > methods > computed attributes > computed dictionary items]
      ought to make its way into the NameMapper discussion in the UG?

      ...Edmund.



      -------------------------------------------------------
      In remembrance
      www.osdn.com/911/
      _______________________________________________
      Cheetahtemplate-discuss mailing list
      Cheetahtemplate-discuss@...
      https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
    • Mike Orr
      ... I saved it as a possible FAQ question. (I m thinking about starting a Cheetah FAQ.) It may belong in the UG, but I m not sure where or how. Do people
      Message 2 of 6 , Sep 11, 2002
        On Wed, Sep 11, 2002 at 08:44:06PM -0400, Edmund Lian wrote:
        > Perhaps this code snippet and the name resolution priority [assigned
        > attributes > methods > computed attributes > computed dictionary items]
        > ought to make its way into the NameMapper discussion in the UG?

        I saved it as a possible FAQ question. (I'm thinking about
        starting a Cheetah FAQ.) It may belong in the UG, but I'm not
        sure where or how.

        Do people have any suggestions regarding a Cheetah FAQ?
        Specifically, I need a guideline for what belongs in the UG or
        DG (Developers' Guide) and what belongs in the FAQ. My thought
        is that the UG is for information applicable to a wide
        cross-section of users, whereas a FAQ is better for narrow
        questions that only affect a few users, or to repeat some info
        from the UG in a way that makes it easier to look up a specific
        problem. A FAQ may also make it easier for ppl to find a specific
        answer. I've gotten comments about how the UG is so big it's hard to
        find something, and when I see questions on the list that I know are in
        the UG, it tells me that maybe the UG is too big for ppl to assimilate
        all the info.

        So I think there may be some material in the UG that should be moved
        to a FAQ, but I'm not sure what. There's also the diminishing
        return of repackaging to consider, and the inconvenience to the
        user of looking through a larger number of documents. By repackaging I
        mean, just moving stuff to a new document causes more work without
        generating new content.

        I guess the FAQ will have to be in LaTeX because I definitely want a
        "one HTML file per question" version and a "one HTML file total"
        version, which the existing docs already do, and it would allow
        ps/txt/pdf versions with no more work. So I guess the format will be
        like the existing UG but with a huge TOC.

        --
        -Mike (Iron) Orr, iron@... (if mail problems: mso@...)
        http://iron.cx/ English * Esperanto * Russkiy * Deutsch * Espan~ol


        -------------------------------------------------------
        In remembrance
        www.osdn.com/911/
        _______________________________________________
        Cheetahtemplate-discuss mailing list
        Cheetahtemplate-discuss@...
        https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
      • Tavis Rudd
        Mike, can you remove this item from the BUGS list you drafted. See my last message for an explanation. We should also make a note about this in the docs.
        Message 3 of 6 , Sep 17, 2002
          Mike,
          can you remove this item from the BUGS list you drafted. See my last message
          for an explanation. We should also make a note about this in the docs.
          Cheers,
          Tavis

          On September 11, 2002 12:58 pm, Edmund Lian wrote:
          > Tavis and Mike,
          >
          > As far as I can tell, when you add an object to the searchList, the
          > NameMapper tries to resolve a placeholder name by looking for a like-named
          > method first, then an attribute, and finally a dictionary item. So, passing
          > in an instance of the following class:
          >
          > class MyObject:
          > def __init__(self):
          > self.apple = 'assigned attribute'
          >
          > def __getitem__(self, name):
          > if name == 'apple':
          > [return 'dictionary item'
          >
          > def __getattr__(self, name):
          > if name == 'apple':
          > return 'computed attribute'
          >
          > def apple(self):
          > return 'method'
          >
          > The NameMapper would resolve $apple to 'assigned attribute'. If this is
          > not present in the instance, then the NameMapper would resolve to 'method'
          > next, followed by 'computed attribute' and then 'dictionary item' last.
          >
          > My question is: How does the NameMapper search an object to resolve a
          > placeholder? Right now the object to be searched presents its data as
          > dictionary items. Is there anyway to help Cheetah find these items? E.g.,
          > implement a keys() method that Cheetah might use when searching, etc.?



          -------------------------------------------------------
          This SF.NET email is sponsored by: AMD - Your access to the experts
          on Hammer Technology! Open Source & Linux Developers, register now
          for the AMD Developer Symposium. Code: EX8664
          http://www.developwithamd.com/developerlab
          _______________________________________________
          Cheetahtemplate-discuss mailing list
          Cheetahtemplate-discuss@...
          https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
        Your message has been successfully submitted and would be delivered to recipients shortly.