Chinaunix首页 | 论坛 | 博客
  • 博客访问: 266962
  • 博文数量: 103
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 705
  • 用 户 组: 普通用户
  • 注册时间: 2013-05-02 16:15
文章分类

全部博文(103)

文章存档

2014年(8)

2013年(95)

我的朋友

分类: Python/Ruby

2013-12-19 11:01:23

#输入流
def FileInputStream(filename):
        try:
                f = open(filename)
                for line in f:
                        for byte in line:
                                yield byte
        except StopIteration,e:
                f.close()
                return

#输出流
def FileOutputStream(inputStream,filename):
        try:
                f = open(filename,"w")
                while True:
                        byte = inputStream.next()
                        f.write(byte)
        except StopIteration,e:
                f.close()
                return


if __name__ == "__main__":
        FileOutputStream(FileInputStream("hello.txt"),"hello2.txt")

阅读(2263) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~