Python Cookbook学习记录 ch2_6/7/8_2013/10/27
摘要:
2.6 处理文件中的每一词a.先获取每一行,再通过split()方法获取每一个词,之后再进行处理for line in open(thefilepath): for word in line.split(): dosomethingwith(word)b.使用生成器(generator),将元素的迭代,和元素的处理分开def words_of_file(thefilepath, line_to_words=str.split): the_file = open(thefilepath): for line in the_file: for word... 阅读全文
posted @ 2013-10-27 21:22 七海之风 阅读(129) 评论(0) 推荐(0)
浙公网安备 33010602011771号