python——第十二天

内置模块或者其他模块学习方式:

dir

help

os模块负责程序与操作系统的交互,提供了访问操作系统底层的接口;即os模块提供了非常丰富的方法用来处理文件和目录。

os:

os.path

遍历C盘代码

import os

from os import path

def scanner_file(url: str):

try:

files = os.listdir(url)

for f in files:

real_url = url + os.sep + f

real_url = path.join(url, f)

if path.isfile(real_url): print(path.abspath(real_url))

else: scanner_file(real_url)

except PermissionError :

pass

if name == "main": scanner_file("C:\Windows")

过滤文件的功能

查找到自己电脑中某个盘符中python文件[xxx.py]

import os

def get_filelists(url):

try:

list_directory = os.listdir(url)

for directory in list_directory:

real_url = url+os.sep+directory

if(os.path.isfile(real_url)):

if(os.path.splitext(real_url)1==".py"):

print(real_url)

else:

get_filelists(real_url)

except PermissionError:

pass

get_filelists("C:")

sys模块:

sys模块这个模块主要用来调整和修改python解释器及相关参数

sys.argv返回一个脚本的完全路径 可以把参数传到输出端

python的垃圾回收机制

引用计数法:

sys.setrecursionlimit(2000)

修改递归最大层数值 使用时一定要标记好

谨慎使用

相关推荐
kyle~7 小时前
FastAPI --- 将业务能力以 API 的形式提供给外部系统
python·fastapi·前后端
aiotto资源分享7 小时前
Python 写 JSON 文件,程序中途退出会留下什么?
java·python·json·jsondecodeerror
梯度下降者8 小时前
Python信号量,条件变量,事件学习
python·条件变量·事件·信号量·线程通信
MSTcheng.8 小时前
【AI应用实战】用 FastAPI + SSE 做一个自己的 AI 聊天网页:流式输出、多轮对话与完整源码
人工智能·python·大模型·fastapi·sse·ai聊天助手
the局外人9 小时前
Python 实战检索优化:BM25、向量与重排
数据库·后端·python
__underline__9 小时前
冷门Python知识点006篇:Python 类体里的名字,能被"凭空造出来"
后端·python
用户03321266636710 小时前
使用 Python 轻松移除 Excel 文档中的重复行
python·excel
LiaoWL12310 小时前
从零搭一个 RAG 知识库(二):换上语义 Embedding——BGE 实测与阈值重校准
python·大模型·numpy·embedding·向量检索·rag
Dmz丶10 小时前
前端转 AI 100 天 Day 48:向量数据库——100 万向量的毫秒级检索
python
青少儿编程课堂10 小时前
蓝桥杯·全国青少年信息素养大赛·电子学会Python/C++考级:中国剩余定理解析
c++·python·算法·bfs·信息学竞赛