Python console rejects an object reference, having made an object with that reference as its name in previous line
Simon Evans
musicalhacksaw at yahoo.co.uk
Sun Dec 14 11:15:38 EST 2014
Dear Python programmers,
Having input the line of code in text:
cd Soup
to the Windows console, and having put the file 'EcologicalPyramid.html' into the Directory 'Soup', on the C drive, in accordance with instructions I input the following code to the Python console, as given on page 30 of 'Getting Started with Beautiful Soup':
----------------------------------------------------------------------------
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("ecologicalpyramid.html","r") as ecological_pyramid:
... soup = BeautifulSoup(ecological_pyramid,"lxml")
... producer_entries = soup.find("ul")
^
SyntaxError: invalid syntax
>>> producer_entries = soup.find("ul")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'soup' is not defined
>>>
^
----------------------------------------------------------------------------
so I cannot proceed with the next line withh would 've been :
----------------------------------------------------------------------------
print(producer_entries.li.div.string)
----------------------------------------------------------------------------
which would've given (according to the book) the output:
---------------------------------------------------------------------------
plants
Maybe that is getting a bit far ahead, but I can't quite see where I have gone wrong - 'soup' has been defined as an object made of file 'EcologicalPyramid.html
I hope you can help me on this point.
Yours
Simon
More information about the Python-list
mailing list