当文件的最后修改时间与本次不同时,重新执行脚本githubinstallation#终端执行pipinstallseeingusingseeinghello.pyseeinghello.goseeing-s3hello.go#查看hello.go的修改时间间隔3秒原理#当脚本修改时间不同时,调用执行脚本的语言。去运行hello.gog++hello.cpp&&./a.outextensionseeing-cshhello.shseeing-copenhello.htmlseeing-cnodehello.jsseeing-cscrapyspider.pycodedefmonitor_file_modify_every(seconds,filename,command):#当文件的最后修改时间与这次不同时,重新执行脚本st=os.stat(filename).st_mtimewhileTrue:f=os.stat(filename)ifst!=f.st_mtime:st=f.st_mtimeiffilename.endswith('.cpp'):cmd="g++{}&&./a.out"eliffilename.endswith('.c'):cmd="gcc{}&&./a.out"eliffilename.endswith('.py'):cmd="python{}"eliffilename.endswith('.go'):cmd="gorun{}"else:cmd=command+"{}"操作系统。系统(命令。格式(文件名))尝试:time.sleep(seconds)除了KeyboardInterrupt:os._exit(0)
