[Patches] [ python-Patches-408627 ] frame.lookup_name
noreply@sourceforge.net
noreply@sourceforge.net
Wed, 21 Mar 2001 18:49:07 -0800
Patches item #408627, was updated on 2001-03-14 15:02
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=305470&aid=408627&group_id=5470
Category: core (C code)
Group: None
>Status: Closed
Priority: 5
Submitted By: Jeremy Hylton (jhylton)
Assigned to: Jeremy Hylton (jhylton)
Summary: frame.lookup_name
Initial Comment:
This method implements the functionality you want for
string interpolation: given a frame, return the value
that name is bound to in the frame's environment.
Works for free variables.
----------------------------------------------------------------------
Comment By: Jeremy Hylton (jhylton)
Date: 2001-03-19 12:33
Message:
Logged In: YES
user_id=31392
We decided to scrap this approach, because it does a linear
search over the names in the code object to figure out the
right scope. If you look up all the names, this has
quadratic cost.
Instead, we'll create a dictionary with all the name
bindings.
----------------------------------------------------------------------
Comment By: Ka-Ping Yee (ping)
Date: 2001-03-14 21:53
Message:
Logged In: YES
user_id=45338
I hate SourceForge. It just took three or four tries,
reloading various pages on the looong path between the
login screen and the patch detail screen, to convince
it that i was logged in.
Anyway, here's what i wanted to say: lookup() would be
a fine name for a method, but then again, why not just
use mp_subscript?
----------------------------------------------------------------------
Comment By: Barry Warsaw (bwarsaw)
Date: 2001-03-14 19:48
Message:
Logged In: YES
user_id=12800
Certainly seems to do what I want, thanks. Three questions,
probably for the BDFL:
- is lookup_name() the best name for the method? The
underscore is a little ugly to me.
- should lookup_name() take an optional failobj, a la
dict.get() which, if provided and the name is missing
returns failobj instead of raising NameError? NameError
is fine if failobj is omitted.
- does it make sense to be able to find out where a name
was found, i.e. in which scope? I can't think of a
particular use for this, but the API might be for
frame.which_scope(name) to return an integer which
signifies how many lexical scopes up the name was found.
e.g. 0 == locals, 1 == immediately nested scope and
so on. Maybe special value -1 means global.
Ah, on second thought, that seems more confusing than
necessary.
Assigning back to Jeremy.
----------------------------------------------------------------------
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=305470&aid=408627&group_id=5470