python-时间、计划程序、启动程序

1、python的时间函数

Unix时间戳是一个浮点值和整型值,表示自1970年1月1日午夜0点(UTC)以来的秒数

datetime:包含一些整型值,保存在year、month、day、hour、minute、second属性中

timedelta:表示一段时间,不是一个特定的时刻

time.time():返回浮点值,表示当前时刻的Unix纪元时间戳

time.sleep(seconds):程序暂停secondes指定的秒数

datetime.datetime(year,month,day,hour,minute,second):返回指定时刻的datetime对象

datetime.datetime.now():返回当前时刻的datetime对象

datetime.datetime.fromtimestamp(epoch):返回epoch时间戳表示的时刻的datetime对象

datetime.timedelta(weeks,days,hours,minutes,seconds,milliseconds,microseconds):返回一个表示一段时间的timedelta对象

total_seconds():返回timedelta对象表示的秒数

strftime(format):返回一个字符串,用format字符串中的定制格式表示datetime对象的时间

datetime.datetime.strptime(time_string,format):返回一个datetime对象,它的时刻由time_string指定,用format字符串参数来解析

2、创建线程 threading.Thread(target=待执行方法名称)

代码如下:

import threading

threadObj=threading.Thread(target=print,args=['cats','dogs','frogs'],kwargs={'sep':'&'})        #print是方法名称,args是print传入的参数值

threadObj.start()        #启动线程

3、python启动其他程序        Popen()函数

subprocess是python自带的模块,可直接导入

代码如下:

import subprocess

subprocess.Popen('c:\\Windows\\System32\\calc.exe')

subprocess.Popen(['c:\\python37\\python.exe','hello.py'])

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值