Why doesn't input code return 'plants' as in 'Getting Started with Beautiful Soup' text (on page 30) ?

Albert Visser albert.visser at gmail.com
Sun Jul 12 20:34:18 CEST 2015


On Sun, 12 Jul 2015 19:33:17 +0200, Simon Evans  
<musicalhacksaw at yahoo.co.uk> 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 "<stdin>", line 2
>     soup = BeautifulSoup(f,"lxml")
>        ^
> IndentationError: expected an indented block
>>>> soup = BeautifulSoup(f,"lxml")
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
> 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"

"Expected an indented block" means that the indicated line should have  
started with at least one whitespace character more than the preceding  
line.

  >>> with open("C:\Beautiful Soup\ecologicalpyramid.html","r")as f:
  ... soup = BeautifulSoup(f,"lxml")

should have been something like

  >>> with open("C:\Beautiful Soup\ecologicalpyramid.html","r")as f:
  ...     soup = BeautifulSoup(f,"lxml")
-- 
Vriendelijke groeten / Kind regards,

Albert Visser

Using Opera's mail client: http://www.opera.com/mail/


More information about the Python-list mailing list