python的windows 自动化【demo】

  1. 【原始】打开记事本
def createFile(filename):
    if os.path.exists(filename) == False:
        open(filename, "a").close()
    if os.path.getsize(filename):
        pass
    else:
        f = open(filename, "a")
        f.write("多喝水!!")
        f.close()


def printTips(filename):
    createFile(filename);
    sub2 = subprocess.Popen(['notepad', filename]);

  1. 【win32com】打开记事本
import win32com.client

o = win32com.client.Dispatch("Excel.Application")
o.Visible = 1
o.Workbooks.Add() # for office 97 – 95 a bit different!
o.Cells(1,1).Value = "Hello"
posted @ 2021-07-20 14:24  该显示昵称已被使用了  阅读(114)  评论(0编辑  收藏  举报