python技巧总结--持续更新
2015-07-15 21:19
218 查看
1.获取某一文件夹下所有文件路径
file_path = []
path = r""
for parent,dirnames,filenames in os.walk(path):
for filename in filenames:
#print "the full name the file is" + os.path.join(parent,filename)
file_path.append(os.path.join(parent,filename))
2.字符串是否以特定字符结尾
str1.endswith("str2")
3.list comprehension
l2 = [i.split(".php")[0] for i in l1 if i.endswith(".php")]
4.dict返回值
dict.setdefault('key', 'b')
如果字典中"key"存在返回所对应的value,若不存在返回"b"
file_path = []
path = r""
for parent,dirnames,filenames in os.walk(path):
for filename in filenames:
#print "the full name the file is" + os.path.join(parent,filename)
file_path.append(os.path.join(parent,filename))
2.字符串是否以特定字符结尾
str1.endswith("str2")
3.list comprehension
l2 = [i.split(".php")[0] for i in l1 if i.endswith(".php")]
4.dict返回值
dict.setdefault('key', 'b')
如果字典中"key"存在返回所对应的value,若不存在返回"b"
相关文章推荐
- Python垃圾回收机制
- Python.Scrapy.14-scrapy-source-code-analysis-part-4
- python3.4学习笔记(二十三) Python调用淘宝IP库获取IP归属地返回省市运营商实例代码
- python实现爬虫下载美女图片
- 【Python】容器类
- 【Python 学习手册笔记】列表与字典
- A Neural Network in 11 lines of Python
- VS2012 + SWIG Python
- python字符串/元组/列表/字典互转
- Python.Scrapy.12-scrapy-source-code-analysis-part-2
- Python实现快速多线程ping的方法
- python_metaclass浅析
- Python新式类和经典类的区别
- 浅谈Python Web的五大框架
- 修饰器
- Python Windows下文件读写与二进制读写的区别
- python中的构造函数
- Python.Scrapy.11-scrapy-source-code-analysis-part-1
- Python-文件修改器
- 【Python】 Flask 缘分匹配练手项目