-
每3秒打印一次任务
'''
使用pip安装schedule包,并指定安装源
pip install -i http://mirrors.aliyun.com/pypi/simple/ schedule --trusted-host mirrors.aliyun.com
'''
#每3秒执行一次打印
import schedule
import time
a = 1
def djob(a):
print("这是第{0}次执行".format(a))
schedule.every(1).seconds.do(djob,a)
while a<10:
djob(a)
time.sleep(3)
a+=1
-
判断文件是否存在,并写入内容
def mkdir(path):
# 引入模块
import os
# 去除首位空格
path = path.strip()
# 去除尾部 \ 符号
path = path.rstrip("\\")
# 判断路径是否存在
# 存在 True
# 不存在 False
isExists = os.path.exists(path)
# 判断结果
if not isExists:
# 如果不存在则创建目录
# 创建目录操作函数
os.makedirs(path)
print(path + ' 创建成功')
return True
else:
# 如果目录存在则不创建,并提示目录已存在
print(path + ' 目录已存在')
return False
#Print text into the file
def print_to_file():
fp = open('D:/test.txt','a+')
print('Good~',file=fp)
fp.close()
if __name__ == '__main__':
mkdir('D:/test')
print_to_file()
-
打印九九乘法表
for i in range(1,10,1):
for j in range(1,i+1,1):
print(i,'*',j,'=',i*j,end='\t')
print()