Python windows interactive.
Steve Holden
steve at holdenweb.com
Mon Oct 30 21:42:23 EST 2006
notejam wrote:
> Thanks everyone for the help. I got a simple two line program to work
> from a text file.
> Can not figure out how to write more than one line in interpreter mode.
> Is that all interpreter is good for, testing one liners? I have it
> run the program everytime I hit return, and can not figure out how to
> enter multiple lines of code. I can do multiple lines in text file, so
> no problem, but I am jsut wondering can a program with 2 or more lines
> be wrote from the interpreter mode?
>
The interactive interpreter is mostly for experimentation, but of course
its advantage is that you can test out complex functionality imported
from modules and packages. Want to know what's on the Google home page?
>>> import urllib
>>> f = urllib.urlopen("http://www.google.com")
>>> data = f.read()
>>> print data
<html><head><meta http-equiv="content-type" content="text/html;
charset=ISO-8859
-1"><title>Google</title><style><!--
body,td,a,p,.h{font-family:arial,sans-serif}
.h{font-size:20px}
.q{color:#00c}
--></style>
<script>
<!--
function sf(){document.f.q.focus();}
// -->
</script>
</head><body bgcolor=#ffffff text=#000000 link=#0000cc vlink=#551a8b
alink=#ff0000 onload=sf() topmargin=3 marginheight=3><center><div
align=right nowrap style="padding-bottom:4px" width=100%><font size=-1> ...
<font size=-2>©2006 Google</font></p></center></body>
</html>
>>>
You can also define funcitons and classes, and write multi-line
statements interactively once you learn the conventions, but once
functionality "hardens" into something of five lines or more that you
want to experiment with you will find it's usually easier to edit a
script or program in a text file and run it. This is even more the case
when you start to use "test-driven development", something we shoudl all
aspire to.
regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden
More information about the Python-list
mailing list