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代码,实现遍历该路径下的所有文 件

>>>

相关推荐
白雨青1 小时前
国信 iQuant 自动国债逆回购实战:Python 自动化闲钱理财
python·量化策略·量化交易·国债逆回购
流水迢迢lst1 小时前
靶场练习day15--php反序列化
开发语言·php
于先生吖1 小时前
国际版JAVA婚恋交友系统源码:多语言适配,可商用的跨境婚恋解决方案
java·大数据·交友
fengci.1 小时前
ctfshow(web入门)279-286
java·开发语言·学习
fy121631 小时前
navicat15安装破解
java
TON_G-T1 小时前
javascript中 Iframe 处理多端通信、鉴权
开发语言·前端·javascript
周淳APP1 小时前
【JS之闭包防抖节流,this指向,原型&原型链,数据类型,深浅拷贝】简单梳理啦!
开发语言·前端·javascript·ecmascript
ok_hahaha1 小时前
java从头开始-苍穹外卖day05-Redis及店铺营业状态设置
java·开发语言·redis
2501_933329551 小时前
舆情监测系统的技术演进:从数据采集到AI中台,Infoseek如何实现“监测+处置”一体化
开发语言·人工智能·自然语言处理·系统架构