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

Laurent Pointal laurent.pointal at free.fr
Sun Jul 12 19:54:01 CEST 2015

Simon Evans wrote:

> ---------------------------------------------------------------------
>>>> with open("C:\Beautiful Soup\ecologicalpyramid.html","r") as

You seem to run Python under Windows.

You have to take care of escape mechanism beyond \ char in string literals 
(see Python docs). 

By chance, \B and \e are not recognized as escape sequences, so they are 
left as is. But \a \b \f \n \r \t \v \x  will be processed differently

Double \ in your string:
	"C:\\Beautiful Soup\\ecologicalpyramid.html"

Or use a raw string by prepending a r to disable escape sequences:
	r"C:\Beautiful Soup\ecologicalpyramid.html"



More information about the Python-list mailing list