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"
上一篇:各个版本的python在windows上如何安装pywin32


下一篇:Python 处理excel文件时遇到报错:AttributeError: module 'win32com.gen_py.00020813-0000-0000-C000-000000000