[Tutor] a bug I cannot solve myself ;-)

Andre Engels andreengels at gmail.com
Thu Mar 25 10:54:49 CET 2010


2010/3/25 spir ☣ <denis.spir at gmail.com>:
> Hello,
>
>
> I'm writing a kind of language simulation. Here, an expression like "a#3.b" maps to a NamedData node, with an attribute terms=[('.','a'),('#',3),('.'''b')].
> (The lang uses '#' instead of "[...]" for item indexing.)
> When this node is "run", the source code maps to a name lookup operation in current scope, passing the terms attr as argument. Below the code with debug prints and the error I get and cannot understand:
>
> ==================
> class Scope(Code):
>    ...
>    @staticmethod
>    def lookup(scope, terms):
>        ''' actual data refered to by name (or context) terms'''
>        data = scope    # actually, initial container
>        for term in terms:
>            (sign,key) = term
>            print data, (sign,ATTR,sign==ATTR,sign is ATTR), key
>            if sign == "ATTR":    # sign == ATTR='.'
>                print "getAttr"
>                data = data.getAttr(key)
>            else:                 # sign == ITEM='#'
>                print "getItem"
>                data = data.getItem(key) ####### line 82 #######
>        return data
> === output =======
> currentScope ('.', '.', True, True) a
> getItem
> ... traceback ...
>  File "/home/spir/prog/python/claro/scope.py", line 82, in lookup
>    data = data.getItem(key)
> AttributeError: 'Scope' object has no attribute 'getItem'
> ==================
>
> (Scopes actually have no getIem, they're plain symbol (attribute) containers.)
>
> There must be something such obvious I'm too stupid to see it! What do I overlook? How can it branch to the "getItem" side of the choice?


if sign == "ATTR":

should be

if sign == ATTR:


-- 
André Engels, andreengels at gmail.com


More information about the Tutor mailing list