Re: ANNOUNCE: Thesaurus - a recursive dictionary subclass usingattributes

Discussion in 'Python' started by Dave Cinege, Dec 11, 2012.

  1. Dave Cinege

    Dave Cinege Guest

    On Tuesday 11 December 2012 01:41:38 Ian Kelly wrote:

    > running into bugs like this:
    > >>> thes = Thesaurus()
    > >>> thes.update = 'now'
    > >>> thes.update

    >
    > <built-in method update of Thesaurus object at 0x01DB30C8>


    I've noticed this but it's mostly pointless, as meaningful code does work.
    (Also you stepped on the existing 'update()' dictionary method.)

    >>> import thesaurus
    >>> t = thesaurus.Thesaurus()
    >>> t.s = 'now'
    >>> t.s + ' this'

    >'now this'


    Works perfect. However I'll take a look at __getattribute__ as from what you
    say it's more proper.

    > Second, in __getitem__ you start a loop with "for i in
    > range(len(l)):", and then you use i as an index into l several times.
    > It would be cleaner and more Pythonic to do "for i, part in
    > enumerate(l):", and then you can replace every occurrence of "l"


    My python is still 'old school' due to being stuck on old versions for in
    production embedded system python applications.

    > It's not clear to me what the isinstance call here is meant to be
    > testing for.


    It's used to determine if it's the root instance of the recursive string
    because self.data, not self must be used to access that. Can you offer a better
    way?

    > The prior statements require key to be a string. If key
    > is a string, then by construction l[0] is also a string. So it seems
    > to me that the isinstance check here will always be False.


    OK, try and remove it and then get back to me. :)

    > In any case, the key splitting here seems to be done primarily to
    > support the use of formatting placeholders like "%(L.l.1)s" in the
    > examples. I want to point out that this use case is already well
    > supported (I might even say "better" supported since it cleanly
    > distinguishes index elements from attributes with syntax) by the


    Thesaurus recursion works with modules like Template, in addition to allowing
    easy hierarchical organization of (global) data. It's not about string
    formatting. It's about organizing data and recursive retrieval of that data.

    > Lastly, you have several bare "except" clauses in the code. Bare


    Not going to get into religion. There is no 'correct' way to do this code at
    all because it's not established normal python. I left it simple and it suits
    my needs. I've converted several production commercial utilities and
    applications to use Thesaurus, and have seen nothing but benefit.

    If anyone needs more to this, have at it, I'm busy

    Dave
    Dave Cinege, Dec 11, 2012
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jason Friedman
    Replies:
    0
    Views:
    110
    Jason Friedman
    Dec 11, 2012
  2. Ian Kelly
    Replies:
    0
    Views:
    131
    Ian Kelly
    Dec 11, 2012
  3. Ian Kelly
    Replies:
    0
    Views:
    151
    Ian Kelly
    Dec 11, 2012
  4. Ian Kelly
    Replies:
    0
    Views:
    130
    Ian Kelly
    Dec 11, 2012
  5. Dave Cinege
    Replies:
    0
    Views:
    140
    Dave Cinege
    Dec 11, 2012
Loading...

Share This Page