python--os和os.path模块

>>> import os

>>> #curdir #获取当前脚本的绝对路径

>>> os.curdir

'.'

>>> import os.path

>>> #获取绝对路径
>>> os.path.abspath(os.curdir)

'C:\\Users\\GUOGUO'

>>> #chdir #修改当前目录
>>> os.chdir("../")

>>> os.path.abspath(os.curdir)

'C:\\Users'
>>> #打印cpu线程
>>> os.cpu_count()

12
>>> #获取当前路径
>>> os.getcwd()

'C:\\Users'
>>> #获取进程编号
>>> os.getpid()

61340
>>> #查看多进程
>>> os.getppid()

62024
>>> #获取系统名称
>>> os.name

'nt'

>>> #文件分割符

>>> os.sep

'\\'

>>> os.listdir()

'All Users', 'Default', 'Default User', 'desktop.ini', 'GUOGUO', 'Public'

>>> #查看当前文件夹所有文件夹名称

>>> os.scandir()

<nt.ScandirIterator object at 0x0000018BAE3A6850>

>>> re = os.scandir()

**>>> os.path

<module 'ntpath' (frozen)>
>>> from os import path**

>>>

>>> path

<module 'ntpath' (frozen)>

>>> dir(path)

'abspath', 'altsep', 'basename', 'commonpath', 'commonprefix', 'curdir', 'defpath', 'devnull', 'dirname', 'exists', 'expanduser', 'expandvars', 'extsep', 'genericpath', 'getatime', 'getctime', 'getmtime', 'getsize', 'isabs', 'isdevdrive', 'isdir', 'isfile', 'isjunction', 'islink', 'ismount', 'join', 'lexists', 'normcase', 'normpath', 'os', 'pardir', 'pathsep', 'realpath', 'relpath', 'samefile', 'sameopenfile', 'samestat', 'sep', 'split', 'splitdrive', 'splitext', 'splitroot', 'stat', 'supports_unicode_filenames', 'sys'

>>>

>>>

>>> path.abspath(".")

'C:\\Users'

>>> path.altsep

'/'

>>> #查找文件名称

>>> f = "C:\\Users"

>>> path.basename(f)

'Users'

>>>

>>> path.exists(f)

True

>>> #'getatime', 'getctime', 'getmtime',文件访问时间,文件创建时间,文件修改时间

>>> #isabs 判断是不是绝对路径 ismount判断是否挂载'

>>> 拼接路径 path.join()

>>>

>>> #面试题 给定一个路径(如: d://),使用python代码,实现遍历该路径下的所有文 件

>>>

相关推荐
23图12 分钟前
C 语言开散列表(拉链法)拆解:链挂得没错,key=-1 会去读 T[-1]
c语言·开发语言·散列表
feixing_fx1 小时前
解构与展开:可读性和性能的取舍
开发语言·前端·javascript·前端框架
小飞在努力1 小时前
【实现负载均匀在线判题③】从零散模块到统一,编译运行全链路封装
c语言·开发语言·c++·笔记
Logintern091 小时前
deep agents 多智能体模式——规划与委派
python·langchain
Flynt2 小时前
Spring AI Alibaba 真停更了?我把它的 GitHub 翻了个底朝天
java·spring·开源
2601_967980113 小时前
Python 办公自动化合集 ⑰:Excel自动计算——总和/平均分/最大值
python·pycharm·办公自动化·数据处理·excel自动计算
饮水桶_T5 小时前
C++ stack & queue复习笔记
开发语言·笔记·算法
她的男孩5 小时前
Spring Boot 接 Flowable:请假单要同时走财务和行政,包容分支和默认分支怎么配
java·spring boot·工作流引擎
炸膛坦客5 小时前
单片机/C/C++八股:(三十四)C 语言函数参数入栈顺序
c语言·开发语言·c++
databook5 小时前
时间序列预测,模型换了一圈为什么没变好
python·数据分析