python 代码遍历一个简单文档的段落(7 行“第 1 行”、“第 2 行”等)。我希望每个段落对象都是唯一的,但实际上我得到了重复,在这种情况下0x25173368
。怎么了?这完全违背我的直觉。
编码:
import win32com.client as win32
word = win32.GetObject(Class="Word.Application")
doc = word.Documents.Open("test.docx")
for para in doc.Paragraphs:
print repr(para)
输出:
<win32com.gen_py.Microsoft Word 12.0 Object Library.Paragraph instance at 0x25173368>
<win32com.gen_py.Microsoft Word 12.0 Object Library.Paragraph instance at 0x25427240>
<win32com.gen_py.Microsoft Word 12.0 Object Library.Paragraph instance at 0x25173368>
<win32com.gen_py.Microsoft Word 12.0 Object Library.Paragraph instance at 0x25427280>
<win32com.gen_py.Microsoft Word 12.0 Object Library.Paragraph instance at 0x25173368>
<win32com.gen_py.Microsoft Word 12.0 Object Library.Paragraph instance at 0x25427320>
<win32com.gen_py.Microsoft Word 12.0 Object Library.Paragraph instance at 0x25173368>