Python代码总结
来源:互联网 发布:sql日期取年月日 编辑:程序博客网 时间:2024/05/16 19:14
OS
os.walk(dirpath)返回一个三元组(dirpath,dirnames,filenames),其中第一个dirpath(string)是搜索目录,第二个dirnames(list)为搜索目录下的所有文件夹,第三个filenames(list)为搜索目录下所有的文件。
for dirpath,dirnames,filenames in os.walk(rootdir):
for dirname in dirnames:
print(dirname)
for filename in filenames:
print(filename)
filenames不包含路径信息,使用全路径: os.path.join(dirpath,filename)。
获取文件名和扩展名:
name=file.split(‘.’)[0]
ext=file.split(‘.’)[-1]
获取当前目录
os.getcwd()
//获取目录下的所有文件名
os.listdir(dir)
//删除文件
os.remove()
//运行shell命令
os.system(”)
//分割目录和文件名
(dir,file)=os.path.split();
//判断文件或目录
os.path.isdir()
os.path.isfile()
os.path.exists()
//获取文件大小
os.path.getsize()
//分离文件名和扩展名
(file,ext)=os.path.splitext()
//连接目录和文件名
os.path.join(dir,file)
字符串操作
字符串连接
‘%s,%s’%(‘str1’,’str2’)
str_list=[‘str1’,’str2’,’str3’]
op=’##’
op.join(str_list)
- Python代码总结
- Python 代码编程问题总结
- Python第三方库代码总结
- Python文本处理常用代码总结(一)
- Python文本处理常用代码总结(二)
- Python文本处理常用代码总结(三)
- Python代码调试的几种方法总结
- 钓鱼网站规则提取工作的python代码重写总结
- python代码
- Python代码
- Python代码
- python 代码
- python代码
- 代码总结
- 代码总结
- 总结代码
- 代码总结
- 代码总结
- hdoj Primes Problem 5104 (素数打表&&技巧)
- Activity的4种launchMode
- ADS编译问题
- android 底片,浮雕,老照片效果
- JS----setCookie,getCookie,delCookie
- Python代码总结
- mysql忘记密码找回
- 读书笔记Cocos2d-x之工厂方法
- 编写一个写字板初步了解Winform编程(一)——Winform程序结构
- SVN服务器搭建和使用(一)
- nginx+tomcat7+redis集群配置
- 网络收集javaScript中常用的基本验证
- SVN服务器搭建和使用(二)
- Unix学习笔记------书本例题编程实例------从标注输入读入然后从标准输出输出