Path: csiph.com!usenet.pasdenom.info!news.redatomik.org!newsfeed.xs4all.nl!newsfeed7.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; 'lines,': 0.05; "subject:' ": 0.07; 'subject:code': 0.07; 'defined.': 0.09; 'executes': 0.09; 'nameerror:': 0.09; 'subject:Getting': 0.09; 'subject:Why': 0.09; 'typed': 0.09; 'python': 0.10; 'syntax': 0.13; 'subject: \n ': 0.15; 'error"': 0.16; 'executed,': 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'message- id:@mrabarnett.plus.com': 0.16; 'received:192.168.1.4': 0.16; 'received:84.93': 0.16; 'received:84.93.230': 0.16; 'soup': 0.16; 'subject:Started': 0.16; 'wrote:': 0.16; 'subject:page': 0.18; 'suggested': 0.20; '(the': 0.22; '"",': 0.22; '12th': 0.22; 'code,': 0.23; 'defined': 0.23; 'bit': 0.23; 'second': 0.24; 'import': 0.24; '(most': 0.24; 'header:In-Reply-To:1': 0.24; 'header:User-Agent:1': 0.26; 'error': 0.27; 'code': 0.30; 'skip:s 30': 0.31; 'received:84': 0.32; 'errors,': 0.33; 'traceback': 0.33; 'file': 0.34; 'nov': 0.35; 'expected': 0.35; "isn't": 0.35; 'there': 0.36; '(and': 0.36; 'to:addr:python-list': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'received:192': 0.39; 'to:addr:python.org': 0.40; 'subject:with': 0.40; 'more': 0.63; 'dear': 0.67; 'sunday': 0.72; '2013,': 0.91 X-CM-Score: 0.00 X-CNFS-Analysis: v=2.1 cv=OoyysHLt c=1 sm=1 tr=0 a=0nF1XD0wxitMEM03M9B4ZQ==:117 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=0Bzu9jTXAAAA:8 a=EBOSESyhAAAA:8 a=AGkejYDSTmIA:10 a=IkcTkHD0fZMA:10 a=_03PaXIkjM07k3_bU5oA:9 a=QEXdDO2ut3YA:10 X-AUTH: mrabarnett@:2500 Date: Sun, 12 Jul 2015 19:05:22 +0100 From: MRAB User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Why doesn't input code return 'plants' as in 'Getting Started with Beautiful Soup' text (on page 30) ? References: <1e75fe53-743b-4432-8b4e-6897b3d54956@googlegroups.com> In-Reply-To: <1e75fe53-743b-4432-8b4e-6897b3d54956@googlegroups.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit 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: 33 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1436724512 news.xs4all.nl 2862 [2001:888:2000:d::a6]:33505 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:93740 On 2015-07-12 18:33, Simon Evans wrote: > > Dear Peter Otten, > I typed in (and did not copy and paste) the code as you suggested just now (6.28 pm, Sunday 12th July 2015), this is the result I got: > ---------------------------------------------------------------------------- > 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") > File "", line 2 > soup = BeautifulSoup(f,"lxml") > ^ > IndentationError: expected an indented block >>>> soup = BeautifulSoup(f,"lxml") > Traceback (most recent call last): > File "", line 1, in > NameError: name 'f' is not defined >>>> > ---------------------------------------------------------------------------- > The first time I typed in the second line, I got the > "Indentation error" > the second time I typed in exactly the same code, I got the: > "NameError:name 'f' is not defined" > Python parses the lines, and, if there are no syntax errors, it then executes them. That block of code (the 2 lines) contained a syntax (indentation) error in the second line, so _none_ of the block was executed, and, therefore, 'f' isn't defined.