Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #79197
| From | Dennis Lee Bieber <wlfraed@ix.netcom.com> |
|---|---|
| Subject | Re: Import Doesn't Import |
| Date | 2014-10-15 22:11 -0400 |
| Organization | IISS Elusive Unicorn |
| References | <1a3844da-b467-43ba-b34f-3aaa6442d799@googlegroups.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.14910.1413425511.18130.python-list@python.org> (permalink) |
On Wed, 15 Oct 2014 17:40:25 -0700 (PDT), ryguy7272 <ryanshuell@gmail.com>
declaimed the following:
>Fetching URLs
>The simplest way to use urllib2 is as follows:
>import urllib2
>response = urllib2.urlopen('http://python.org/')
>html = response.read()
>
Works fine in Python 2.7
PythonWin 2.7.5 (default, Sep 16 2013, 23:11:01) [MSC v.1500 64 bit
(AMD64)] on win32.
Portions Copyright 1994-2008 Mark Hammond - see 'Help/About PythonWin' for
further copyright information.
>>> import urllib2
>>> response = urllib2.urlopen("http://python.org/")
>>> html = response.read()
>>> print html
<!doctype html>
<!--[if lt IE 7]> <html class="no-js ie6 lt-ie7 lt-ie8 lt-ie9">
<![endif]-->
<!--[if IE 7]> <html class="no-js ie7 lt-ie8 lt-ie9"> <![endif]-->
<!--[if IE 8]> <html class="no-js ie8 lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--><html class="no-js" lang="en" dir="ltr">
<!--<![endif]-->
<head>
>
>It immediately produces this error:
>Traceback (most recent call last):
> File "C:/Python34/import_web_data.py", line 1, in <module>
> import urllib2
>ImportError: No module named 'urllib2'
>
>
>ImportError: No module named 'urllib2'
>I'm telling Python to import because it doesn't exist and it throws an error. I don't get it; I just don't get it. If I'm working with R, I can import thousands of libraries with no errors whatsoever. With Python, I just get thousands of errors with nothing working whatsoever. I totally don't understand this language. Import means import. Right. WTF!!!!!
Well, you are using Python 3.4 -- there were significant changes made
in the transition from 2.x to 3.x. 90% of the stuff you find on the web is
probably written against Python 2.x -- if the example uses
print "some stuff %s" % ("or other",)
if is 2.x, while
print("some stuff %s" % ("or other",))
if could be 2.x (the extra () don't affect 2.x print statement) but is more
likely to be 3.x (though 3.x likely is also using a different formatter
than the old % string interpolation).
The best documentation is the supplied help system -- the library
reference manual in particular. Glancing at that would reveal that 3.x does
not have a urllib2 module (and the documentation in 2.7.5 even states:
"""
Note
The urllib2 module has been split across several modules in Python 3 named
urllib.request and urllib.error. The 2to3 tool will automatically adapt
imports when converting your sources to Python 3.
"""
--
Wulfraed Dennis Lee Bieber AF6VN
wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Import Doesn't Import ryguy7272 <ryanshuell@gmail.com> - 2014-10-15 17:40 -0700
Re: Import Doesn't Import ryguy7272 <ryanshuell@gmail.com> - 2014-10-15 17:44 -0700
Re: Import Doesn't Import Dan Stromberg <drsalists@gmail.com> - 2014-10-15 18:19 -0700
Re: Import Doesn't Import Terry Reedy <tjreedy@udel.edu> - 2014-10-15 22:43 -0400
Re: Import Doesn't Import Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-10-16 09:01 +0100
Re: Import Doesn't Import Chris Angelico <rosuav@gmail.com> - 2014-10-16 11:54 +1100
Re: Import Doesn't Import Dan Stromberg <drsalists@gmail.com> - 2014-10-15 18:12 -0700
Re: Import Doesn't Import MRAB <python@mrabarnett.plus.com> - 2014-10-16 02:13 +0100
Python 3 is the active language, recommended for newcomers (was: Import Doesn't Import) Ben Finney <ben+python@benfinney.id.au> - 2014-10-16 12:35 +1100
Re: Import Doesn't Import Chris Rebert <clp2@rebertia.com> - 2014-10-15 18:21 -0700
Re: Import Doesn't Import Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2014-10-15 22:11 -0400
Re: Import Doesn't Import Emile van Sebille <emile@fenx.com> - 2014-10-16 14:29 -0700
Re: Import Doesn't Import Joel Goldstick <joel.goldstick@gmail.com> - 2014-10-16 18:28 -0400
Re: Import Doesn't Import Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-10-16 23:56 +0100
csiph-web