Python console rejects an object reference, having made an object with that reference as its name in previous line

Dave Angel davea at davea.name
Sun Jan 4 09:14:52 EST 2015


On 01/04/2015 07:49 AM, Simon Evans wrote:
> Dear Michael Torrie,
> Thanks for pointing that out to me re: it not being a syntax problem.
> The thing is there is a file called 'EcologicalPyramid.html'. I put it in a folder called 'Soup' as the text advised on page 28.
> For what its worth I also shifted the Windows Command Prompt to that folder (re: cd Soup)as instructed on page 30,
> and put a duplicate file of 'EcologicalPyramid.html' in the python 2.8 directory.

Never put any user files in the "python 2.8" directory, whatever that is.

> I therefore am wondering where I ought put this html file where the Python console will recognize it ?

Since your code expects it in the current directory, either change the 
code, or make sure it IS in the current directory.

The only obvious thing I can see is that you didn't spell the name the 
same.  But since Windows makes the error of ignoring case, it ought to 
be close enough.  However, you're typing the name, not pasting it, so 
maybe there's some other subtle difference, like you have more than one 
Soup directory.

Try the following, from the cmd.exe prompt:

myprompt> cd Soup
myprompt> dir *.html
   (something shows here)
myprompt> python
   (something shows here)


 >>> from bs4 import BeautifulSoup
 >>> with open("ecologicalpyramid.html","r") as ecological_pyramid:
...      soup= next(ecological_pyramid,"lxml")
...      producer_entries = soup.find("ul")
...

and see what happens.  Paste the whole thing into a message if it 
doesn't make sense to you.  And of course don't forget to include the 
traceback.



-- 
DaveA



More information about the Python-list mailing list