Whats missing?
Michael P. Reilly
arcege at shore.net
Tue Jun 1 15:39:08 EDT 1999
Daniel Faulkner <m01ymu00 at cwcom.net> wrote:
: I was just messing about and found out that if I made some thing like
: this it would not work but if I did it by typing at the python prompt
: from urllib import urlopen
: Data = urlopen("http://www.python.org/").read()
: print Data
: It would work but why is this?
: from Tkinter import *
: from urllib import urlopen
: class HTMLBrowser(Frame):
: def Create_Widgets(self):
: # frames
: butFrame = Frame()
: butFrame.pack(side='top')
: # normal widgets
: self.QuitB = Button(butFrame, text='Quit', fg='red',
: command=self.quit)
: self.UrlEnt = Entry(self, relief=SUNKEN)
: self.source_box = Text(self)
: self.startB = Button(butFrame, text='Start',
: command=self.UrlGeting)
: # Pack it
: self.QuitB.pack(side='left')
: self.startB.pack(side='left')
: self.UrlEnt.pack(side='top', fill='x')
: self.source_box.pack(side='bottom')
: def lets_see_it(self):
: self.source_box.insert('0.0', self.Data)
: def UrlGeting(self):
: UrlCurr = self.UrlEnt.get()
: Data = urlopen('"' + UrlCurr + '"').read()
Off-hand, I would say it is the quoting here.
This statement is adding double quotes to the URL. UrlCurr is already
a string, you do not need to enclose it in quotes.
urlopen("http://www.python.org/spam").read()
is the same as:
url = "http://www.python.org/spam"
urlopen(url).read()
The statement above is attempting to call:
urlopen("\"http://www.python.org/spam\"").read()
: self.source_box.insert('0.0', Data)
: def __init__(self, master=None):
: Frame.__init__(self, master)
: self.pack()
: self.Create_Widgets()
: # Test
: Dat = urlopen("http://www.python.org/")
: # print Dat
: Browser = HTMLBrowser()
: Browser.mainloop()
More information about the Python-list
mailing list