1、python 官方标准的模块 https://docs.python.org/zh-cn/3.8/library/index.html
2、对常用模块的一些归纳 https://python.libhunt.com/
3、https://pynative.com/
示例
1、列出目录下文件使用glob递归查询,使用os.listdir列出当前层级目录或文件,或者用walk模块
import glob
dir_path = 'C:\\Users\ming.li\Desktop\pythontest\**\*.*'
for file in glob.glob(dir_path, recursive=True): recursive(递归的方式)
print(file)
2、显示从给定日期后的多少天
from datetime import datetime
import pandas as pd
start_date = datetime.strptime("2022-10-20", "%Y-%m-%d")
# periods means how many dates you want
date_list = pd.date_range(start_date, periods=5, freq='D')
print(f"Creating list of 5 dates starting from {start_date}")
print(date_list)
3、文件操作
fp = open('sales.txt', 'rwxabt')(权限选其中一个)
fp.write('first line')(如果权限是w会每次覆盖不是追加)
fp.close()
或者
with open("C:\\Users\\minglong.li\\Desktop\\pythontest\\test.txt", 'a') as fp: (使用with自动关闭对象)
fp.write("this is a test")
#以日期位文件名
import time
filename = time.strftime("%d-%m-%Y")
files = filename + '.txt'
print(filename)
with open(files, 'a') as fp:
fp.write("this is a test\n")
with open(files, 'r') as fp:
content = fp.read()
print(content)