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)

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

谨慎使用

相关推荐
用户83562907805114 小时前
Python 实现 PDF 文件加密与解密方法
后端·python
用户83562907805114 小时前
使用 Python 冻结与拆分 Excel 窗格教程
后端·python
你好潘先生1 天前
别再记命令了,用 yeero do 说句人话就能跑脚本,而且不烧 token
服务器·python·命令行
Agent_大师1 天前
WebSocket 行情重连成功,K线缺口不会自动消失
python
荣码1 天前
LLM结构化输出:让AI返回JSON而不是废话,我踩了4个坑
java·python
copyer_xyf1 天前
FastAPI 如何连接 MySQL
后端·python
apocelipes2 天前
常用编程语言和库的正则表达式性能对比
c语言·c++·python·性能优化·golang·开发工具和环境
用户8356290780512 天前
使用 Python 在 PDF 中创建与管理书签
后端·python
MeixianAgent2 天前
Python 回测数据入口怎么验?历史 K 线入库前先做 5 个检查
后端·python
咕白m6252 天前
用 Python 实现一键批量查找与替换 Excel 数据
后端·python