[Tutor] fish or fowl?
Pijus Virketis
virketis@fas.harvard.edu
Thu, 3 Jan 2002 14:39:02 +0200
This is a multi-part message in MIME format.
------=_NextPart_000_023B_01C19464.6364DEC0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Dear all,=20
here is a little thing I have been wondering for a while. In Python, I =
can say something like this:
>>> if raw_input() =3D=3D "f": print "foo"
I get a prompt, and upon entering "f", foo is printed. Very nice, very =
convenient. Now, here's the question: how does the raw_input() call =
actually get evaluated? Is there a variable assignment going on in the =
background? As if I had typed:
>>> input_string =3D raw_input()
>>> if input_string =3D=3D "f": print "foo"
Or is there some other behaviour? Can I retrieve the value afterwards? I =
guess I am just curious what happens under the hood here.=20
Cheers,=20
Pijus
------=_NextPart_000_023B_01C19464.6364DEC0
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2712.300" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Dear all, </FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>here is a little thing I have been =
wondering for a=20
while. In Python, I can say something like this:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>>>> if raw_input() =3D=3D "f": =
print=20
"foo"</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>I get a prompt, and upon entering "f", =
foo is=20
printed. Very nice, very convenient. Now, here's the question: how does =
the=20
raw_input() call actually get evaluated? Is there a variable assignment =
going on=20
in the background? As if I had typed:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>>>> input_string =3D=20
raw_input()</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>>>> if input_string =
=3D=3D "f": print=20
"foo"</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>Or is there some other behaviour? Can I =
retrieve=20
the value afterwards? I guess I am just curious what happens under =
the hood=20
here. </FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>Cheers, </FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>Pijus</FONT></DIV></BODY></HTML>
------=_NextPart_000_023B_01C19464.6364DEC0--