python学习

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)

可以使用zip将多个元组或列表看成一个迭代对象

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值