Path: csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-1.proxad.net!hq-usenetpeers.eweka.nl!hq-usenetpeers.eweka.nl!bcyclone02.am1.xlned.com!bcyclone02.am1.xlned.com!newsfeed.xs4all.nl!newsfeed1a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python,': 0.02; '"""': 0.07; 'error:': 0.07; 'urllib2': 0.07; 'string': 0.09; '%s"': 0.09; '2to3': 0.09; 'portions': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'throws': 0.09; 'python': 0.11; '2.7': 0.14; 'language.': 0.14; 'changes': 0.15; '"some': 0.16; '>the': 0.16; 'imports': 0.16; 'it;': 0.16; 'message-id:@4ax.com': 0.16; 'pythonwin': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'simplest': 0.16; 'statement)': 0.16; 'supplied': 0.16; 'library': 0.18; 'wed,': 0.18; 'bit': 0.19; 'module': 0.19; 'split': 0.19; 'written': 0.21; '(the': 0.22; '>>>': 0.22; 'example': 0.22; 'import': 0.22; 'manual': 0.22; 'print': 0.22; '2.x': 0.24; 'url:home': 0.24; 'fine': 0.24; 'right.': 0.26; 'skip:" 30': 0.26; 'header:X-Complaints-To:1': 0.27; "doesn't": 0.30; 'converting': 0.30; 'errors': 0.30; "i'm": 0.30; '3.x': 0.31; 'libraries': 0.31; 'produces': 0.31; 'sep': 0.31; 'file': 0.32; 'probably': 0.32; 'stuff': 0.32; 'url:python': 0.33; '(most': 0.33; 'sources': 0.33; 'totally': 0.33; 'could': 0.34; 'tool': 0.35; 'but': 0.35; 'there': 0.35; 'skip:> 10': 0.36; 'transition': 0.36; 'charset:us-ascii': 0.36; 'url:org': 0.36; 'error.': 0.37; 'follows:': 0.38; 'to:addr:python-list': 0.38; 'recent': 0.39; 'does': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'even': 0.60; 'skip:u 10': 0.60; 'affect': 0.61; 'further': 0.61; 'telling': 0.64; 'more': 0.64; 'different': 0.65; '3.4': 0.84; '2013,': 0.91; 'received:108': 0.93 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Dennis Lee Bieber Subject: Re: Import Doesn't Import Date: Wed, 15 Oct 2014 22:11:39 -0400 Organization: IISS Elusive Unicorn References: <1a3844da-b467-43ba-b34f-3aaa6442d799@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: adsl-108-68-178-170.dsl.klmzmi.sbcglobal.net X-Newsreader: Forte Agent 6.00/32.1186 X-No-Archive: YES X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 68 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1413425511 news.xs4all.nl 2850 [2001:888:2000:d::a6]:42875 X-Complaints-To: abuse@xs4all.nl X-Received-Body-CRC: 3360850814 X-Received-Bytes: 6044 Xref: csiph.com comp.lang.python:79197 On Wed, 15 Oct 2014 17:40:25 -0700 (PDT), ryguy7272 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 > >It immediately produces this error: >Traceback (most recent call last): > File "C:/Python34/import_web_data.py", line 1, in > 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/