摘要: 1. 最基本的读文件方法:file = open("sample.txt") while 1: line = file.readline() if not line: break pass # do something 一行一行得从文件读数据,显然比较慢;不过很省内... 阅读全文
posted @ 2014-10-20 17:18 arhatlohan 阅读(324) 评论(0) 推荐(0) 编辑
摘要: 一、单行注释单行注释以#开头,例如:print 6#输出6二、多行注释(Python的注释只有针对于单行的注释(用#),这是一种变通的方法)多行注释用三引号'''将注释括起来,例如:'''多行注释多行注释'''三、中文注释在文件头上写入:#coding=gbk或:#coding=utf-8虽然#这个... 阅读全文
posted @ 2014-10-20 16:00 arhatlohan 阅读(562) 评论(0) 推荐(0) 编辑
摘要: 使用正则表达式可以很好解决import res = 'Hello!This?Is!What?I!Want'ss = re.split('[!?]', s) ss = ['Hello', 'This', 'Is', 'What', 'I', 'Want'] 阅读全文
posted @ 2014-10-20 11:06 arhatlohan 阅读(1122) 评论(0) 推荐(0) 编辑