Path: csiph.com!usenet.pasdenom.info!news.redatomik.org!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!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; 'subject:text': 0.04; 'error:': 0.05; "subject:' ": 0.07; 'subject:code': 0.07; 'nameerror:': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:Getting': 0.09; 'subject:Why': 0.09; 'python': 0.10; 'output': 0.13; 'properly': 0.15; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-ipconnect.de': 0.16; 'recognise': 0.16; 'reproduce': 0.16; 'soup': 0.16; 'subject:Started': 0.16; 'which,': 0.16; 'wrote:': 0.16; 'subject:page': 0.18; '>>>': 0.20; '"",': 0.22; 'defined': 0.23; 'bit': 0.23; 'seems': 0.23; 'import': 0.24; '(most': 0.24; 'header:User-Agent:1': 0.26; 'header:X-Complaints-To:1': 0.26; 'skip:s 30': 0.31; 'traceback': 0.33; 'file': 0.34; 'nov': 0.35; 'expected': 0.35; 'to:addr :python-list': 0.36; 'subject:: ': 0.37; 'received:org': 0.37; 'detail': 0.38; 'thank': 0.38; 'to:addr:python.org': 0.40; 'subject:with': 0.40; 'received:de': 0.40; 'your': 0.60; 'more': 0.63; 'dear': 0.67; 'reply': 0.68; '2013,': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Peter Otten <__peter__@web.de> Subject: Re: Why doesn't input code return 'plants' as in 'Getting Started with Beautiful Soup' text (on page 30) ? Date: Sun, 12 Jul 2015 14:26:28 +0200 Organization: None References: Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Gmane-NNTP-Posting-Host: p57bd9b91.dip0.t-ipconnect.de User-Agent: KNode/4.13.3 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ 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: 46 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1436704006 news.xs4all.nl 2939 [2001:888:2000:d::a6]:50244 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:93733 Simon Evans wrote: > Dear Peter Otten, thank you for your reply that I have not gone very far > into the detail of which, as it seems Python console cannot recognise the > name 'f' as given it, re output below : > > > Python 2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)] > on win 32 > Type "help", "copyright", "credits" or "license" for more information. > >>>> from bs4 import BeautifulSoup >>>> with open("C:\Beautiful Soup\ecologicalpyramid.html","r")as f: >>>> soup = BeautifulSoup(f, "lxml") > Traceback (most recent call last): > File "", line 1, in > NameError: name 'f' is not defined >>>> Is that copy-and-paste? When I try to reproduce that I get $ python Python 2.7.6 (default, Jun 22 2015, 17:58:13) [GCC 4.8.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> from bs4 import BeautifulSoup >>> with open("C:\Beautiful Soup\ecologicalpyramid.html","r")as f: ... soup = BeautifulSoup(f, "lxml") File "", line 2 soup = BeautifulSoup(f, "lxml") ^ IndentationError: expected an indented block and when I indent the soup = ... line properly I don't get an error: $ python Python 2.7.6 (default, Jun 22 2015, 17:58:13) [GCC 4.8.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> from bs4 import BeautifulSoup >>> with open("C:\Beautiful Soup\ecologicalpyramid.html","r")as f: ... soup = BeautifulSoup(f, "lxml") ... >>>