import time
start = time.time()
for i in range(10):
print(i)
end = time.time()
end-start
timeit module
def test():
l = []
for i in range(1000):
l.append(i)
import timeit
t = timeit.Timer("test()", "from __main__ import test")
# from __main__ import test1 imports the function test1
# from the __main__ namespace into the namespace that
# timeit sets up for the timing experiment.
print(t.timeit(number=1000), "milliseconds")
2. 修改文件名字
import os
# 改变当前工作目录
os.chdir('C:/Users/dingx/Documents/Python_tmp')
# 获取当前文件夹下文件名
files=os.listdir()
for filename in files:
# 删除每个文件名的前三个字
newname = filename[3:]
# 改名字
os.rename(filename , newname)