Why does this fail?
Mel Wilson
mwilson at the-wire.com
Sun Jan 4 20:20:22 EST 2004
In article <vvhdlm72386b3c at corp.supernews.com>,
"Dave Murray" <dlmurray at micro-net.com> wrote:
>New to Python question, why does this fail?
>
>---testcase.py---
>import sys, urllib, htmllib
>def Checkit(URL):
> try:
> print "Opening", URL
> f = urllib.open(URL)
> f.close()
> return 1
> except:
Here, try
except Exception, details
print "Exception:", details
> return 0
>
>rtfp = Checkit("http://www.python.org/doc/Summary.html")
>if rtfp == 1:
> print "OK"
>else:
> print "Fail"
Then you'll see
Opening http://www.python.org/doc/Summary.html
Exception: 'module' object has no attribute 'open'
Fail
You probably mean urlopen .
Regards. Mel.
More information about the Python-list
mailing list