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


Groups > comp.lang.python > #4824 > unrolled thread

Re: BeautifulSoup import error

Started bynirinA raseliarison <nirina.raseliarison@gmail.com>
First post2011-05-06 15:27 +0300
Last post2011-05-06 15:27 +0300
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

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

#4824 — Re: BeautifulSoup import error

FromnirinA raseliarison <nirina.raseliarison@gmail.com>
Date2011-05-06 15:27 +0300
SubjectRe: BeautifulSoup import error
Message-ID<mailman.1243.1304684825.9059.python-list@python.org>
[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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web