[python-chinese] 是用word com时出现的问题
nF n
windhere在gmail.com
星期五 九月 1 22:15:35 HKT 2006
不对...Paragraphs(index)
返回的是一个paragraph对象,它并没有encode方法,
只是有到string 的转换,就是转换的过程中有的问题...
暂时的理解...-.- 怎么解决阿..555
On 9/1/06, ainulinde <ainulinde at gmail.com> wrote:
>
> 好像结果是unicode的,试试
> print doc.Paragraphs(1).encode('cp936')
>
> On 9/1/06, nF n <windhere at gmail.com> wrote:
> >
> > w = win32com.client.Dispatch('Word.Application')
> > doc = w.Documents.Open('test.txt')
> > print doc.Paragraphs(1)
> >
> > 若第一段里有中文,
> > 则会出现以下错误
> > Traceback (most recent call last):
> > File "H:/Py/doctest.py", line 31, in -toplevel-
> > print doc.Paragraphs(1)
> > File
> > "D:\Python24\Lib\site-packages\win32com\client\dynamic.py",
> > line 187, in __str__
> > return str(self.__call__())
> > File
> > "D:\Python24\Lib\site-packages\win32com\client\dynamic.py",
> > line 187, in __str__
> > return str(self.__call__())
> > UnicodeEncodeError: 'ascii' codec can't encode characters in position
> 0-7:
> > ordinal not in range(128)
> >
> > 请问如何解决此问题?
> >
> > _______________________________________________
> > python-chinese
> > Post: send python-chinese at lists.python.cn
> > Subscribe: send subscribe to
> > python-chinese-request at lists.python.cn
> > Unsubscribe: send unsubscribe to
> > python-chinese-request at lists.python.cn
> > Detail Info:
> > http://python.cn/mailman/listinfo/python-chinese
> >
> _______________________________________________
> python-chinese
> Post: send python-chinese at lists.python.cn
> Subscribe: send subscribe to python-chinese-request at lists.python.cn
> Unsubscribe: send unsubscribe to python-chinese-request at lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://python.cn/pipermail/python-chinese/attachments/20060901/9cf4ed72/attachment.html
关于邮件列表 python-chinese 的更多信息