- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
当我尝试按原样运行此代码时,出现此错误“IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, pythoncom.IID_IDispatch) pywintypes.com_error: (-2147221008, 'CoInitialize has not been called.', None, None)",但是如果我单独运行 stp_tracker 它工作正常,如果我单独运行 notify stp's 它工作得很好。我感谢任何人的意见。谢谢
import time
import win32com.client
# import sys
from watchdog.observers import Observer
from watchdog.events import PatternMatchingEventHandler
# import watchdog
class MyHandler(PatternMatchingEventHandler):
patterns = ["*.stp", "*.step", "*.txt"]
def process(self, event):
"""
event.event_type
'modified' | 'created' | 'moved' | 'deleted'
event.is_directory
True | False
event.src_path
path/to/observed/file
"""
# the file will be processed there
print(event.src_path, event.event_type)
def on_modified(self, event):
self.process(event)
notify_stps()
def on_created(self, event):
self.process(event)
notify_stps()
def on_deleted(self, event):
self.process(event)
notify_stps()
def stp_tracker():
# /if __name__ == '__main__':
path = r"W:\TestFolder"
observer = Observer()
observer.schedule(MyHandler(), path)
observer.start()
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
observer.stop()
observer.join()
def notify_stps():
const = win32com.client.constants
olMailItem = 0x0
obj = win32com.client.Dispatch("Outlook.Application")
newMail = obj.CreateItem(olMailItem)
newMail.Subject = "I AM SUBJECT!!"
newMail.Body = "Step files in directory"
# newMail.BodyFormat = 2 # olFormatHTML https://msdn.microsoft.com/en-us/library/office/aa219371(v=office.11).aspx
# newMail.HTMLBody = "<HTML><BODY>Enter the <span style='color:red'>message</span> text here.</BODY></HTML>"
newMail.To = 'Acoker251@outlook.com'
# attachment1 = r"C:\Temp\example.pdf"
# newMail.Attachments.Add(Source=attachment1)
newMail.Send()
stp_tracker()
最佳答案
首先:
import pythoncom
然后设置:
xl=win32com.client.Dispatch("Excel.Application",pythoncom.CoInitialize())
关于python - pywintypes.com_error : (-2147221008, 'CoInitialize has not been called.',无,无),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61071022/
今天突然出现以下错误。 import win32com.client xl=win32com.client.Dispatch("Excel Application") Traceback (most
我在使用 Python 编写脚本时遇到以下错误。 错误2010年1月19日星期二14:51:21 C:\Python24\Lib\site-packages\win32com\client\util.
import time from win32com import client from win32com.client import constants as c import os wb = xl
我的以下代码片段运行良好。它创建一个图表并将其类型设置为 xlLine chart = ws.Shapes.AddChart().Select() xl.ActiveChart.ChartType =
我想做的就是打开一个 .xlsm 文件,运行宏,保存工作簿,然后退出。理想情况下,我可以将宏作为变量传递,因为不同的情况会运行位于同一工作簿中的不同宏。这是到目前为止的代码。 import os, s
我在这里使用用户 Augustin 发布的解决方案:very quickly getting total size of folder folderPath = r"C:\Users\e46ldc\D
我正在尝试使用 pyrtd Python获取信息的模块,可以通过RTD在Excel中获取信息。 但是,当我尝试运行 sample python script ,我收到以下错误: pywintypes.
有没有人可以提供在 excel 中创建数据透视图的示例代码?我有一个使用数据透视表创建数据透视表的示例,它有效,而当我尝试以相同的方式创建数据透视图时,它总是失败! import win32com.c
我需要从三个 Excel 文件复制数据并粘贴到三个不同的 Excel 文件中。 Error: ('F', 'C:\\Users\\jmp655972\\Desktop\\SOFTWARE D
我在运行模块 gasprop 时遇到此错误。我不明白错误的含义以及如何解决它: import gasprop Traceback (most recent call last): File "", l
我改编了以下代码发现here在我现有的 Excel 工作表中创建数据透视表: import win32com.client as win32 win32c = win32.constants impo
当我尝试按原样运行此代码时,出现此错误“IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, pythoncom.IID_ID
我正在使用 python 在 word 中打开一个 word 文档并尝试使用 this 转换它在 StackOverflow 上回答。 我的 python 代码: import win32com.cl
我正在尝试使用 xlwings 将数据验证添加到 Excel 工作表范围: def set_validation(rng): """Add data validation to the giv
我正在使用 Excel 和 xlwings。我有一个 book.xlsm,在第一张纸上有一个分配给以下 vba 代码的按钮: book.xlsm!ThisWorkbook.get_data 在 VBA
我正在使用 Python 3.2.2,并构建了一个 Tkinter 界面来进行一些 Active Directory 更新。我在尝试处理 pythoncom.com_error 异常时遇到问题。 我从
我打开了一个 Excel,其中包含 RTD 流数据(来自交易平台的财务数据)。我的目标是通过Python读取数据并在数据发生变化时立即保存。目标是捕捉每一毫秒。我正在使用 xlwings 读取单元格值
从 excel 表生成 pdf 时出现以下错误: ws.ExportAsFixedFormat(0, save_as) File ">", line 5, in ExportAsFixedForm
我正在使用 Excel、Python 和 Visio,当我运行这个简单的代码时,出现错误 com_error: (-2147023174, 'The RPC server is unavailable
我是从创建的示例 http://docs.xlwings.org/en/stable/vba.html/Python 3.5.1 |Anaconda 2.5.0(32 位)| (默认,2016年1月2
我是一名优秀的程序员,十分优秀!