摘要: #链接mysql#插入数据import MySQLdbconn = MySQLdb.connect(host = '127.0.0.1',user = 'root',passwd = '',db = 'mytest')cur = conn.cursor()reConn = cur.execute(" 阅读全文
posted @ 2016-06-20 20:56 3one 阅读(175) 评论(0) 推荐(0) 编辑
摘要: 1、异常处理使用Exception类,也可自定义异常 2、异常处理流程: try: pass except Exception,e pass else: pass finally: pass 3、手动触发异常raise 阅读全文
posted @ 2016-06-12 17:08 3one 阅读(91) 评论(0) 推荐(0) 编辑
摘要: #!/usr/bin/env python# _*_ coding:utf-8 _*_# 面向对象'''class Province: province = '23个省之一' # 静态字段 # __init__ 是构造函数 def __init__(self, name, capital, lead 阅读全文
posted @ 2016-06-08 16:52 3one 阅读(102) 评论(0) 推荐(0) 编辑
摘要: python 装饰器Decorator #在不改变函数代码的情况下,添加功能 import timedef timeDecorator(func): def getTime(args): t0 = time.time() re = func(args)print re print "执行%s耗时%f 阅读全文
posted @ 2016-05-31 22:08 3one 阅读(97) 评论(0) 推荐(0) 编辑
摘要: #反射的作用在于模块导入,函数调用时简化代码 以URL为例: 假设URL的形式是A/B #!/usr/bin/env python# _*_ coding:utf-8 _*_# 常规'''from backend import login,logout,admindata = raw_input(' 阅读全文
posted @ 2016-05-30 21:48 3one 阅读(271) 评论(0) 推荐(0) 编辑
摘要: # 随机数 生成验证码import random# print random.random()# print random.randint(1, 5)# print random.randrange(1, 5)# temp = random.randint(65, 90)# print chr(te 阅读全文
posted @ 2016-05-30 17:06 3one 阅读(460) 评论(0) 推荐(0) 编辑
摘要: import timeimport reprint time.time()print time.localtime()a = 'tm_year=2016, tm_mon=5, tm_mday=28, tm_hour=6, tm_min=51, tm_sec=14, tm_wday=5, tm_yda 阅读全文
posted @ 2016-05-28 17:35 3one 阅读(144) 评论(0) 推荐(0) 编辑
摘要: import reresult1 = re.match('\d+', '1sssda22wdasfsa') # 匹配开头print type(result1)print result1if result1: print result1.group()else: print 'nothing'resu 阅读全文
posted @ 2016-05-28 14:40 3one 阅读(230) 评论(0) 推荐(0) 编辑
摘要: pickle能序列化常规数据类型(元组、列表、字典、集合等),也可以序列化非常规类型(类、函数等),基本上是所以得数据类型,只能python程序使用。 Python file类型在Python是一个特殊的类型。 json 只能序列化常规类型,任何语言都可以。 ###pickle import pic 阅读全文
posted @ 2016-05-27 15:29 3one 阅读(148) 评论(0) 推荐(0) 编辑