<font><i>self</i>.doc.Tables(</font><font color="#800000"><font color="#800000">1</font></font><font>).Cell(row,</font><font color="#800000"><font color="#800000">2</font></font><font>) is not a string, and therefore has no .split() method.<br>
</font><font>str(<i>self</i>.doc.Tables(</font><font color="#800000"><font color="#800000">1</font></font><font>).Cell(row,</font><font color="#800000"><font color="#800000">2</font></font><font>)) returns a string, so it does have a split() method and therefore<br>
</font><font>str(<i>self</i>.doc.Tables(</font><font color="#800000"><font color="#800000">1</font></font><font>).Cell(row,</font><font color="#800000"><font color="#800000">2</font></font><font>)).split() is </font>correct, but<br>
<font><font>str(<i>self</i>.doc.Tables(</font><font color="#800000"><font color="#800000">1</font></font><font>).Cell(row,</font><font color="#800000"><font color="#800000">2</font></font><font>).split()) is not. Note the different position on the double parens ))<br>
--<br>Vernon<br></font></font><br><div class="gmail_quote">On Thu, Mar 8, 2012 at 10:14 AM, cool_go_blue <span dir="ltr"><<a href="mailto:cool_go_blue@yahoo.com">cool_go_blue@yahoo.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td style="font:inherit" valign="top"><div>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:</div>
<div> </div><font>
<p align="left"></p></font><font color="#0000ff"><font color="#0000ff">for</font></font><font> row </font><font color="#0000ff"><font color="#0000ff">in</font></font><font> range(</font><font color="#800000"><font color="#800000">1</font></font><font>,len(<i>self</i>.doc.Tables(</font><font color="#800000"><font color="#800000">1</font></font><font>).Rows)+</font><font color="#800000"><font color="#800000">1</font></font><font>):
<p align="left"></p></font><font color="#0000ff"><font color="#0000ff"> for</font></font><font> word </font><font color="#0000ff"><font color="#0000ff">in</font></font><font> str(<i>self</i>.doc.Tables(</font><font color="#800000"><font color="#800000">1</font></font><font>).Cell(row,</font><font color="#800000"><font color="#800000">2</font></font><font>)).split():
<p align="left"></p></font><font color="#0000ff"><font color="#0000ff"> if</font></font><font> word </font><font color="#0000ff"><font color="#0000ff">not</font></font><font> </font><font color="#0000ff"><font color="#0000ff">in</font></font><font> stopwords:
<div></div></font><font color="#0000ff"><font color="#0000ff"> print</font></font><font> word</font>
<div><font></font> </div>
<div><font>But I get a runtime error when I have the following code:</font></div>
<div><font></font> </div><font><font>
<p align="left">content = [[word </p></font><font color="#0000ff"><font color="#0000ff">for</font></font><font> word </font><font color="#0000ff"><font color="#0000ff">in</font></font><font> str(<i>self</i>.doc.Tables(</font><font color="#800000"><font color="#800000">1</font></font><font>).Cell(row,</font><font color="#800000"><font color="#800000">2</font></font><font>).split()) </font><font color="#0000ff"><font color="#0000ff">if</font></font><font> word </font><font color="#0000ff"><font color="#0000ff">not</font></font><font> </font><font color="#0000ff"><font color="#0000ff">in</font></font><font> stopwords]
<p align="left"></p></font><font color="#0000ff"><font color="#0000ff">for</font></font><font> row </font><font color="#0000ff"><font color="#0000ff">in</font></font><font> range(</font><font color="#800000"><font color="#800000">1</font></font><font>,len(<i>self</i>.doc.Tables(</font><font color="#800000"><font color="#800000">1</font></font><font>).Rows)+</font><font color="#800000"><font color="#800000">1</font></font><font>)]</font>
<p align="left"><font></font>
</p><p align="left"><font>The error is as follows:</font>
</p><p align="left"><font></font> <font><font color="#ff0000"><font color="#ff0000">
</font></font></font></p><p align="left"><font><font color="#ff0000"><font color="#ff0000">Traceback (most recent call last):
</font></font></font></p><p align="left"></p><p></p><font><u><font color="#000080"><font color="#000080">File "J:\MyProjects\Python\VectorSpaceTry\src\ReadCorpus.py", line 111, in <module></font></font></u></font><p>
</p><p></p><p></p></font><font color="#ff0000"><font color="#ff0000">
<p align="left">array.setup()
</p><p align="left"></p><p></p></font></font><u><font color="#000080"><font color="#000080">File "J:\MyProjects\Python\VectorSpaceTry\src\ReadCorpus.py", line 79, in setup</font></font></u><font color="#ff0000"><font color="#ff0000">
<p align="left">for row in range(1,len(self.doc.Tables(1).Rows)+1)
</p><p align="left"></p><p></p></font></font><u><font color="#000080"><font color="#000080">File "F:\Softwares\Working\Languages\Python27\lib\site-packages\win32com\client\__init__.py", line 465, in __getattr__</font></font></u><font color="#ff0000"><font color="#ff0000">
<p align="left">raise AttributeError("'%s' object has no attribute '%s'" % (repr(self), attr))
</p><p align="left">AttributeError: '<win32com.gen_py.Microsoft Word 14.0 Object Library.Cell instance at 0x51383312>' object has no attribute 'split'
</p><p align="left">
</p><p align="left">what is wrong with my code? Thanks.<span class="HOEnZb"><font color="#888888">
</font></span></p><p align="left"><font color="#888888">B.</font></p><p></p><p></p><p></p><p></p></font></font></td></tr></tbody></table><br>_______________________________________________<br>
python-win32 mailing list<br>
<a href="mailto:python-win32@python.org">python-win32@python.org</a><br>
<a href="http://mail.python.org/mailman/listinfo/python-win32" target="_blank">http://mail.python.org/mailman/listinfo/python-win32</a><br>
<br></blockquote></div><br>