<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii"><meta name=Generator content="Microsoft Word 14 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
p
        {mso-style-priority:99;
        mso-margin-top-alt:auto;
        margin-right:0in;
        mso-margin-bottom-alt:auto;
        margin-left:0in;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
span.EmailStyle18
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri","sans-serif";}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body lang=EN-US link=blue vlink=purple><div class=WordSection1><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>You have a misplaced parenthesis.&nbsp; The working code has str (&#8230;Cell(&#8230;) ).split() and the failing code has str (&#8230;Cell(&#8230;).split() ) &#8211;in other words, the bad code has split() applied to the argument of str() rather than the result of str().<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p>&nbsp;</o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; paul<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p>&nbsp;</o:p></span></p><p class=MsoNormal><b><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'>From:</span></b><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'> python-win32-bounces+pkoning=equallogic.com@python.org [mailto:python-win32-bounces+pkoning=equallogic.com@python.org] <b>On Behalf Of </b>cool_go_blue<br><b>Sent:</b> Thursday, March 08, 2012 12:15 PM<br><b>To:</b> python-win32@python.org<br><b>Subject:</b> [python-win32] a trivial question<o:p></o:p></span></p><p class=MsoNormal><o:p>&nbsp;</o:p></p><table class=MsoNormalTable border=0 cellspacing=0 cellpadding=0><tr><td valign=top style='padding:0in 0in 0in 0in'><div><p class=MsoNormal>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:<o:p></o:p></p></div><div><p class=MsoNormal>&nbsp;<o:p></o:p></p></div><p><span style='font-size:10.0pt;color:blue'>for</span><span style='font-size:10.0pt'> row <span style='color:blue'>in</span> range(<span style='color:maroon'>1</span>,len(<i>self</i>.doc.Tables(<span style='color:maroon'>1</span>).Rows)+<span style='color:maroon'>1</span>):<o:p></o:p></span></p><p><span style='font-size:10.0pt;color:blue'>&nbsp;&nbsp; for</span><span style='font-size:10.0pt'> word <span style='color:blue'>in</span> str(<i>self</i>.doc.Tables(<span style='color:maroon'>1</span>).Cell(row,<span style='color:maroon'>2</span>)).split():<o:p></o:p></span></p><p><span style='font-size:10.0pt;color:blue'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if</span><span style='font-size:10.0pt'> word <span style='color:blue'>not</span> <span style='color:blue'>in</span> stopwords:<o:p></o:p></span></p><div><p class=MsoNormal><span style='font-size:10.0pt;color:blue'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print</span><span style='font-size:10.0pt'> word</span><o:p></o:p></p></div><div><p class=MsoNormal>&nbsp;<o:p></o:p></p></div><div><p class=MsoNormal><span style='font-size:10.0pt'>But I get a runtime error when I have the following code:</span><o:p></o:p></p></div><div><p class=MsoNormal>&nbsp;<o:p></o:p></p></div><p><span style='font-size:10.0pt'>content = [[word <span style='color:blue'>for</span> word <span style='color:blue'>in</span> str(<i>self</i>.doc.Tables(<span style='color:maroon'>1</span>).Cell(row,<span style='color:maroon'>2</span>).split()) <span style='color:blue'>if</span> word <span style='color:blue'>not</span> <span style='color:blue'>in</span> stopwords]<o:p></o:p></span></p><p><span style='font-size:10.0pt;color:blue'>for</span><span style='font-size:10.0pt'> row <span style='color:blue'>in</span> range(<span style='color:maroon'>1</span>,len(<i>self</i>.doc.Tables(<span style='color:maroon'>1</span>).Rows)+<span style='color:maroon'>1</span>)]<o:p></o:p></span></p><p><span style='font-size:10.0pt'>&nbsp;<o:p></o:p></span></p><p><span style='font-size:10.0pt'>The error is as follows:<o:p></o:p></span></p><p><span style='font-size:10.0pt'>&nbsp;<o:p></o:p></span></p><p><span style='font-size:10.0pt;color:red'>Traceback (most recent call last):<o:p></o:p></span></p><p><u><span style='font-size:10.0pt;color:navy'>File &quot;J:\MyProjects\Python\VectorSpaceTry\src\ReadCorpus.py&quot;, line 111, in &lt;module&gt;<o:p></o:p></span></u></p><p><span style='font-size:10.0pt;color:red'>array.setup()<o:p></o:p></span></p><p><u><span style='font-size:10.0pt;color:navy'>File &quot;J:\MyProjects\Python\VectorSpaceTry\src\ReadCorpus.py&quot;, line 79, in setup<o:p></o:p></span></u></p><p><span style='font-size:10.0pt;color:red'>for row in range(1,len(self.doc.Tables(1).Rows)+1)<o:p></o:p></span></p><p><u><span style='font-size:10.0pt;color:navy'>File &quot;F:\Softwares\Working\Languages\Python27\lib\site-packages\win32com\client\__init__.py&quot;, line 465, in __getattr__<o:p></o:p></span></u></p><p><span style='font-size:10.0pt;color:red'>raise AttributeError(&quot;'%s' object has no attribute '%s'&quot; % (repr(self), attr))<o:p></o:p></span></p><p><span style='font-size:10.0pt;color:red'>AttributeError: '&lt;win32com.gen_py.Microsoft Word 14.0 Object Library.Cell instance at 0x51383312&gt;' object has no attribute 'split'<o:p></o:p></span></p><p><span style='font-size:10.0pt;color:red'>&nbsp;<o:p></o:p></span></p><p><span style='font-size:10.0pt;color:red'>what is wrong with my code? Thanks.<o:p></o:p></span></p><p><span style='font-size:10.0pt;color:red'>B.<o:p></o:p></span></p></td></tr></table><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Calibri","sans-serif"'><o:p>&nbsp;</o:p></span></p></div></body></html>