python中wind32com.client的改进余地 [英] margin of improvement with wind32com.client in python

查看:76
本文介绍了python中wind32com.client的改进余地的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里我正在编写一个检查拼写和语法错误的程序。有没有办法让
得到额外的间距错误错误。如果在用户之间有多个空格,应该通知你有一个额外的间距错误。我们可以用这个检查5级错误。





level-1 ==>单调乏味

level-2 ==>打字错误

level-3 ==>周语法

level-4 ==>改善幅度

level-5 ==>新颖性

这里是我使用的代码,只提供语法和拼写错误



here i am writing a program that is checking for spelling and grammatical mistake. is there a way to
get extra spacing error error .If there is more then one space between the word user should be notified that you have one extra spacing error. can we check 5 level of mistake with this.
i.e

level-1 ==> tedious
level-2 ==> typing mistake
level-3 ==> week grammar
level-4 ==> margin of improvement
level-5 ==> novelty
here is my code am using which give only grammar and spell mistake

#wind32com.client is module for connecting with windows
#os is module for getting information about os directory
#zipfile is used to make zipfile of docx to read images because python-docx
#does not provide a way to get images from docx.

import win32com.client, os
import zipfile
wdDoNotSaveChanges = 0  #use for exist zero
path = os.path.abspath('mistake_image.docx')  #getting docx file directory we did not need to open it in program
                                        #because we are using word application for checking
z = zipfile.ZipFile("mistake_image.docx")      #making zibfile of doc for reading image and data
                                         #in this case we just need images
#print all files in zip archive
all_files = z.namelist()            #getting all file from doc file
#images will exist in side word/media/ directory that is default for maintaining images directory inside word side
images = filter(lambda x: x.startswith('word/media/'), all_files)   #reading only images
print 'images in doc',images      #printing images list on screen
app = win32com.client.gencache.EnsureDispatch('Word.Application')   #requesting for office grammar and spell checker
                                                            #extra spaces may or may no be handle depand on spell checker
                                                            #setting. if spell and grammar is not set to default . program
                                                            #will show no grammar and spelling error.
doc = app.Documents.Open(path)          #saving path of doc file in doc object
print "Grammar: %d" % (doc.GrammaticalErrors.Count,)        #pring grammar error count
print "Spelling: %d" % (doc.SpellingErrors.Count,)          #prinng spelling errors count

app.Quit(wdDoNotSaveChanges)        #exist app using exit 0

推荐答案

您可以随时查看正则表达式。

参见示例< a href =http://www.regular-expressions.info/> http://www.regular-expressions.info/ [ ^ ]



这个简单的表达式将找到文本中所有位置按顺序排列2个或更多空格。

You could always look into Regular Expressions.
See for example http://www.regular-expressions.info/[^]

This simple expression will find all positions in the text where there are 2 or more spaces in sequence.
[ ]{2,}


这篇关于python中wind32com.client的改进余地的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆