[Tutor] Code to open a website
alan.gauld at btinternet.com
Sun Feb 10 02:33:35 CET 2013
On 10/02/13 01:00, mann kann wrote:
> Dear Jedi,
> I wrote my first program but it doesn't open a website as I intended it
> to. Please correct my mistake.
Well, how did you intend it to?
It looks like it probably does open the web site, but it will be hard to
tell since you do nothing with the result.
> def a():
Please use meaningful names.
openURL() or similar would be a useful choice here.
> import urllib.request
> url = "http://www.google.com"
> response = urllib.request.urlopen(url)
Here you open the url and store the response. But then the function ends
and it gets thrown away and the site is closed again.
> g = input("Please enter y or n to go to youtube : ")
You aren't going to YouTube yet, only Google but I assume YouTube is the
intended eventual target?
Again g is not a very meaningful name. 'choice' or similar
would be more helpful.
> if g == "y":
> print("Opening the website")
Here you call you function but again all the action inside is just lost.
> print("kein website")
Where does exit() come from? Usually its from sys but you
don't import from sys anywhere...
Author of the Learn to Program web site
More information about the Tutor