[Python-Dev] PEP 292, Simpler String Substitutions

Guido van Rossum guido@python.org
Wed, 19 Jun 2002 16:23:03 -0400


> > > Overall it isn't bad...it's a little weird to have a method that depends
> > > on sys._getframe(1) (or as the say in Tcl-land "upvar"). It may set a
> > > bad precedent...
> > 
> > No, the real implementation will be in C.  C functions always have
> > access to locals and globals.
> 
> I didn't mean it will be a bad precedent because of the implemention. I
> mean that methods do not usually peak into their caller's variables,
> even from C. What other methods do that?

Dunno about methods, but locals(), globals(), vars() and dir() do this
or something like it.

> I'm still "+0" despite being somewhat uncomfortable with that
> aspect.

I think little would be lost if sub() always required a dict (or
perhaps keyword args, although that feels like a YAGNI now).

I think that the key thing here is to set the precedent of using $ and
the specific syntax proposed, not necessarily to have this as a
built-in string methong.

Note: posixpath.expandvars() doesn't have $$, which is essential, and
leaves unknown variables alone, which we (mostly) agree is not the
right thing to do.

--Guido van Rossum (home page: http://www.python.org/~guido/)