[python-win32] a trivial question

Paul_Koning at Dell.com Paul_Koning at Dell.com
Thu Mar 8 18:19:20 CET 2012


You have a misplaced parenthesis.  The working code has str (...Cell(...) ).split() and the failing code has str (...Cell(...).split() ) -in other words, the bad code has split() applied to the argument of str() rather than the result of str().

               paul

From: python-win32-bounces+pkoning=equallogic.com at python.org [mailto:python-win32-bounces+pkoning=equallogic.com at python.org] On Behalf Of cool_go_blue
Sent: Thursday, March 08, 2012 12:15 PM
To: python-win32 at python.org
Subject: [python-win32] a trivial question

I try to use comprehensions when I am learning Python. After opening a word document, i try to read the 2nd column of a table for each row. I print out the words as follows:


for row in range(1,len(self.doc.Tables(1).Rows)+1):

   for word in str(self.doc.Tables(1).Cell(row,2)).split():

      if word not in stopwords:
         print word

But I get a runtime error when I have the following code:


content = [[word for word in str(self.doc.Tables(1).Cell(row,2).split()) if word not in stopwords]

for row in range(1,len(self.doc.Tables(1).Rows)+1)]



The error is as follows:



Traceback (most recent call last):

File "J:\MyProjects\Python\VectorSpaceTry\src\ReadCorpus.py", line 111, in <module>

array.setup()

File "J:\MyProjects\Python\VectorSpaceTry\src\ReadCorpus.py", line 79, in setup

for row in range(1,len(self.doc.Tables(1).Rows)+1)

File "F:\Softwares\Working\Languages\Python27\lib\site-packages\win32com\client\__init__.py", line 465, in __getattr__

raise AttributeError("'%s' object has no attribute '%s'" % (repr(self), attr))

AttributeError: '<win32com.gen_py.Microsoft Word 14.0 Object Library.Cell instance at 0x51383312>' object has no attribute 'split'



what is wrong with my code? Thanks.

B.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-win32/attachments/20120308/7f1b473c/attachment.html>


More information about the python-win32 mailing list