1 os.path.listdir #以列表的形式展示文件
2 os.path.getmtime #最后修改的时间
3 os.path.join #路径拼接
4
5 import os
6 filenames = "D:\\pycharm workspace\\appiumframework\\report"
7 lists = os.listdir(filenames) 8 print(lists) 9 lists.sort(key=lambda fn:os.path.getmtime(filenames+"\\"+fn)) 10 print(lists[-1]) 11 file = os.path.join(filenames,lists[-1]) 12 print(file)
1 import threading
2 import time
3
4 class Mythreading(threading.Thread):
5 def __init__(self,threadID,name,counter):
6 threading.Thread.__init__(self) #固定格式
7 self.threadID = threadID
8 self.name = name
9 self.counter = counter
10 print("初始化完成")
11 def run(self): #由cpu来处理决定线程间的执行顺序
12 print("开始"+self.name)
13 print_time(self.name,self.counter,5)
14 print("结束"+self.name)
15
16 def print_time(threasName,counter,delay):
17 while counter:
18 time.sleep(delay)
19 print("%s:%s"%(threasName,time.ctime(time.time())))
20 counter -= 1
21
22 #创建线程
23 thread1 = Mythreading(1,"thread1",1)
24 thread2 = Mythreading(2,"thread2",2)
25
26 #开启线程
27 thread1.start()
28 thread2.start()
1 import threading
2 import time
3
4 class Mythreading(threading.Thread):
5 def __init__(self,threadID,name,counter):
6 threading.Thread.__init__(self) #固定格式
7 self.threadID = threadID
8 self.name = name
9 self.counter = counter
10 print("初始化完成")
11 def run(self): #由cpu来处理决定线程间的执行顺序
12 threadLock.acquire() #获得锁,成功获得锁定后返回True,可选的参数timeout不填时将一直阻塞直到获得锁定
13 print_time(self.name,self.counter,3)
14 threadLock.release() #释放锁,开始下一个线程
15
16 def print_time(threasName,counter,delay):
17 while counter:
18 time.sleep(delay)
19 print("%s:%s"%(threasName,time.ctime(time.time())))
20 counter -= 1
21
22 threadLock = threading.Lock()
23 threads = []
24
25 #创建线程
26 thread1 = Mythreading(1,"thread1",1)
27 thread2 = Mythreading(2,"thread2",2)
28
29 #开启线程
30 thread1.start()
31 thread2.start()
32
33 # thread1.join()
34 # thread2.join()
35 threads.append(thread1)
36 threads.append(thread2)
37 for t in threads:
38 t.join() #后边的代码必须等待,等线程运行完成才会往后运行代码
39
40 print("我的的花儿也谢了")
1 import threading
2 from time import sleep, ctime
3 def music(func):
4 for i in range(2):
5 print ("I was listening to %s! %s&