Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #4824

Re: BeautifulSoup import error

References <6584008a.222d5.12fc2f1358d.Coremail.1011_wxy@163.com>
Subject Re: BeautifulSoup import error
From nirinA raseliarison <nirina.raseliarison@gmail.com>
Date 2011-05-06 15:27 +0300
Newsgroups comp.lang.python
Message-ID <mailman.1243.1304684825.9059.python-list@python.org> (permalink)

Show all headers | View raw


[1011_wxy]

> I got a import error when I use Python 3.2 to import BeautifulSoup 3.2.0

the error i see is a SyntaxError.

> Is there any differences between Python 3.2 and other version?

yes. and there is a tool, 2to3, which converts
Python 2.x scripts to work with 3.x.

> And the error message will be as below.
>
>
>>>> from BeautifulSoup import BeautifulSoup
> Traceback (most recent call last):
>   File "<pyshell#2>", line 1, in <module>
>     from BeautifulSoup import BeautifulSoup
>   File "C:\Python32\BeautifulSoup.py", line 448
>     raise AttributeError, "'%s' object has no attribute '%s'" %  
> (self.__class__.__name__, attr)
>                         ^
> SyntaxError: invalid syntax

a quick fix here, change:

     raise AttributeError, "'%s' object has no attribute '%s'"
%(self.__class__.__name__, attr)

to:

     raise AttributeError("'%s' object has no attribute '%s'"
%(self.__class__.__name__, attr))

enclose the string message with parentheses.
at least, you will not get the SyntaxError.
but a better solution is to use 2to3.

i don't use BeautifulSoup, and i'm still stick with
Python2.5.4 on windows, so can't help much.

with Linux, it is just:

   2to3 a_python_file_or_a_dir_package

on windows, i don't know, maybe:

   import subprocess
   subprocess.Popen(('python.exe', 'Tools/Scripts/2to3.py', 'the_package'))

--
nirinA

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: BeautifulSoup import error nirinA raseliarison <nirina.raseliarison@gmail.com> - 2011-05-06 15:27 +0300

csiph-web