我无法使用pywin32打开word文件.我一直在尝试为pywin32找到教程,但没有一个代码可以工作.word文档的位置是c:\ Users\User\Documents\python progs\misc\format for isn.
import win32com.client as win32
word = win32.gencache.EnsureDispatch('Word.Application')
word.Visible = False
word.Documents.Open('C:\\sectarianism.doc')
Traceback (most recent call last):
File "C:\Users\User\Documents\python progs\misc\formatting for isn\formatting.py", line 5, in <module>
word.Documents.Open('C:\\sectarianism.doc')
File "C:\Python25\lib\site-packages\win32com\gen_py\00020905-0000-0000-C000-000000000046x0x8x4\Documents.py", line 96, in Open
, Visible, OpenAndRepair, DocumentDirection, NoEncodingDialog, XMLTransform
com_error: (-2147352567, 'Exception occurred.', (0, u'Microsoft Word', u'This file could not be found.\r (C:\\sectarianism.doc)', u'C:\\Program Files\\Microsoft Office\\Office12\\1033\\WDMAIN11.CHM', 24654, -2146823114), None)
>>>
Run Code Online (Sandbox Code Playgroud) 我正在尝试制作一个自动构建和保存图形的主循环,但是我发现这是不可能的,我需要单独选择每个图形,打开/显示它然后手动保存它。有谁知道如何自动化这个过程。该程序读取一个 csv 文件并从参数中指定的行生成图形。这里是下面的代码,我看不出哪里出错了。
import matplotlib.pyplot as plt
import sys, csv, math
def main():
readAndChart('8to2Ant10Average', 0,1,2, '8to2Ant10: cumulative ethnic and political attacks')
readAndChart('8to2Ant10Average',0,8,9, '8to2Ant10: ethnic and political attacks per turn')
readAndChart('8to2Ant10Average',0,11,12, '8to2Ant10: ethnic and political attacks as a percentage of total attacks')
def roundUp(x,y):
roun = int(math.ceil(x/y))
k = int(roun*y)
return k
def readAndChart(readTitle, r1,r2,r3, graphTitle):
time = []
data1 = []
data2 = []
data3 = []
data4 = []
read = csv.reader(open(readTitle + '.csv', 'rb'))
legend1 = ''
legend2 …Run Code Online (Sandbox Code Playgroud)