[Tutor] a bug I cannot solve myself ;-)
bob gailer
bgailer at gmail.com
Thu Mar 25 18:55:36 CET 2010
On 3/25/2010 5:39 AM, spir ☣ wrote:
> 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?
First you assign data = scope
Then you reassign data = data.getAttr(key) OR data = data.getItem(key)
data no longer refers to scope! Hence the error.
> How can it branch to the "getItem" side of the choice?
>
>
> Denis
> ________________________________
>
> vit esse estrany ☣
>
> spir.wikidot.com
> _______________________________________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
--
Bob Gailer
919-636-4239
Chapel Hill NC
More information about the Tutor
mailing list