Re: Python windows interactive.
- From: Fredrik Lundh <fredrik@xxxxxxxxxxxxxx>
- Date: Tue, 31 Oct 2006 09:25:30 +0100
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>
.
- References:
- Python windows interactive.
- From: notejam
- Re: Python windows interactive.
- From: Larry Bates
- Re: Python windows interactive.
- From: notejam
- Python windows interactive.
- Prev by Date: Re: 3d programming without opengl
- Next by Date: Re: Tkinter Listbox string formatting question - how to kill a dancing snake ?
- Previous by thread: Re: Python windows interactive.
- Next by thread: Re: Python windows interactive.
- Index(es):
Relevant Pages
|