[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
--
http://mail.python.org/mailman/listinfo/python-list