[Tutor] How to deal with strange errors?

dman dman@dman.ddts.net
Fri, 26 Apr 2002 15:26:32 -0500


--qcHopEYAB45HaUaB
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Fri, Apr 26, 2002 at 10:35:15AM -0700, Danny Yoo wrote:
=20
| > 3. Is it possible to rebind input() to it's original built-in function
| >    without restarting the whole machinery.
|=20
| Although 'input' in the global environment is bound to that string now,

Nope.  It was rebound only in the current environment (module-level
scope).

| it's still possible to fix this by going through the __builtin__ module
| and refix things:

Simply delete the local binding.

>>> input
<built-in function input>
>>> input =3D "foo"
>>> input
'foo'
>>> del input
>>> input
<built-in function input>
>>>=20


As for explaining this to new programmers ... first they need to
understand scope before they can understand how "deleteing" the object
makes it "come back".  In this one case I think curly braces are cool
-- wacky nested scope examples in C are easier to visualize with the
braces and with braces in the middle of a block (as opposed to a new
function).  Perhaps throw some braces into the diagrams as you explain
scopes, but say they are just for visualization in the teaching aid
and that python doesn't use them.

HTH,
-D

--=20

How great is the love the Father has lavished on us,
that we should be called children of God!
        1 John 3:1=20
=20
GnuPG key : http://dman.ddts.net/~dman/public_key.gpg


--qcHopEYAB45HaUaB
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iEYEARECAAYFAjzJt/gACgkQO8l8XBKTpRR2qgCfRKt4lt4Dqh6WrffGcBcv/uk4
AIUAoKq0HxYluih4qySxkE2Xu3LncEeq
=Cpqy
-----END PGP SIGNATURE-----

--qcHopEYAB45HaUaB--