Chinaunix首页 | 论坛 | 博客
  • 博客访问: 433983
  • 博文数量: 138
  • 博客积分: 4114
  • 博客等级: 上校
  • 技术积分: 1341
  • 用 户 组: 普通用户
  • 注册时间: 2007-10-14 20:41
文章分类

全部博文(138)

文章存档

2014年(1)

2013年(2)

2012年(78)

2011年(13)

2010年(34)

2009年(10)

我的朋友

分类: LINUX

2012-01-30 15:51:49

发现python到用的时候才知道自己掌握的有多烂了
赶快把今天自己用到的python记下来,免得后面又忘记了

查看目录下的文件
import os
file_set=os.listdir('dirname')

查看文目录是否存在
import os
if os.path.exists('dirname'):
     print 'exists'
else:
     print 'u can create it!'

os.path.isfile('a.txt') #如果不存在就返回False


字符串查找/拼接
lines=open('filename','r').readlines()
file_buffer=''.join(lines)
begin=file_buffer.find('begin_ch')
end=file_buffer.find('end_ch')
fp=open('new_file_name', 'w')
fp.write(file_buffer[begin:end+1])
fp.close
阅读(459) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~