上一页 1 ··· 30 31 32 33 34 35 36 37 38 ··· 48 下一页
摘要: 这里有两个Regex库的使用方法,一个是编译表达式,一个是多重匹配,其中后面那个值得注意。#!/usr/bin/python#coding=gbkimport reregexes=[re.compile(p) for p in ['this','that'] ]text='Does this the match?'print 'Text: %r\n' % textfor regex in regexes: print 'seeking "%s" ->' % regex.pattern, # 阅读全文
posted @ 2013-03-09 23:34 墨迹哥's 阅读(307) 评论(0) 推荐(0) 编辑
摘要: 今天开始学习Python标准库,同时复习前面所学的。该脚本实现的功能是通过类来调用,并搜索指定上下文,#!/usr/bin/pythonimport reclass Regex_input: def __init__(self,task,source): self.source=source self.task=task def regex(self): opt=re.search(self.task,self.source) if opt==None: print 'No Found the task:... 阅读全文
posted @ 2013-03-09 21:37 墨迹哥's 阅读(404) 评论(0) 推荐(0) 编辑
摘要: #!/usr/bin/pythonmylist=['item']assert len(mylist)>=1mylist.pop()assert len(mylist)>=1 阅读全文
posted @ 2013-03-09 13:03 墨迹哥's 阅读(218) 评论(0) 推荐(0) 编辑
摘要: lambda 只能接单表达式。。#!/usr/bin/python#coding=gbk#创建新的函数对象,并在运行时返回def make_repeater(n): return lambda s: s*ndef inter_up(k): return lambda s: s+ktwice=make_repeater(2)twice2=inter_up('word')print twice2('hello,')print twice('hello')print twice(10) 阅读全文
posted @ 2013-03-09 12:55 墨迹哥's 阅读(317) 评论(0) 推荐(0) 编辑
摘要: 有注释#!/usr/bin/python#coding=gbklistone=[2,3,4,5,6]#复制并乘以大于2的数字listtwo=[2*i for i in listone]print listtwo#把数字放入这个列表listthree=[i for i in listone]print listthree 阅读全文
posted @ 2013-03-09 11:41 墨迹哥's 阅读(245) 评论(0) 推荐(0) 编辑
上一页 1 ··· 30 31 32 33 34 35 36 37 38 ··· 48 下一页