Python windows interactive.

Fredrik Lundh fredrik at pythonware.com
Tue Oct 31 03:25:30 EST 2006


notejam wrote:

> Can not figure out how to write more than one line in interpreter mode.

press return between the lines.  if you get a "..." prompt, keep adding
more lines to the current statement.  press return an extra time to end 
the multiline-statement.

> Is that all interpreter is good for, testing one liners?  I have it
> run the program everytime I hit return

no, it executes the *current statement* when you press return.  a 
program consists usually consists of many statements.

> and can not figure out how to enter multiple lines of code. 

if you'd entered a statement that actually consisted of multiple lines, 
you'd noticed (try entering an "if"-statement, for example).

> I am jsut wondering can a program with 2 or more lines
> be wrote from the interpreter mode?

Type "help", "copyright", "credits" or "license" for more information.
 >>> import urllib
 >>> def gettitle(url):
...     f = urllib.urlopen(url)
...     s = f.read()
...     i = s.find("<title>")
...     j = s.find("</title>", i)
...     return s[i+7:j]
...
 >>> gettitle("http://www.python.org")
'Python Programming Language -- Official Website'
 >>> gettitle("http://www.cnn.com")
'CNN.com - Breaking News, U.S., World, Weather, Entertainment & 
Video News'
 >>> sites = ["http://news.bbc.co.uk", "http://reddit.com",
... "http://www.fbi.gov"
... ]
 >>> for site in sites:
...     print gettitle(site)
...
BBC NEWS | News Front Page
reddit.com: what's new online
Federal Bureau of Investigation - Home Page
 >>>

etc.

</F>




More information about the Python-list mailing list