随笔分类 -  【Python】

摘要:采用装饰器来建立单例模式 def singleton(cls): # 创建一个字典用来保存类的实例对象 _instance = {} def _singleton(*args, **kwargs): # 先判断这个类有没有对象 if cls not in _instance: _instance[c 阅读全文
posted @ 2022-03-22 13:38 小泥巴2008 阅读(247) 评论(0) 推荐(0)
摘要:一: 通过lambda表达式来指定排序字段 salaries = [{'Alice': 100000, 'Bob': 24000}, {'Alice': 121000, 'Bob': 48000}, {'Alice': 12000, 'Bob': 66000}] Use the sorted() f 阅读全文
posted @ 2021-01-08 11:00 小泥巴2008 阅读(1561) 评论(0) 推荐(0)
摘要:使用multiprocessing 使用multiprocessing.dummy 单使用multiprocessing模块的指的是多进程,使用multiprocessing.dummy则表示使用的是多线程 阅读全文
posted @ 2016-06-08 13:53 小泥巴2008 阅读(322) 评论(0) 推荐(0)
摘要:实际开发过程当中可能要对某些方法或者流程做出改进,添加监控,添加日志记录等所以我们要去改动已有的代码,自己的或者别人的,但改动后测试不周会引发不可控的异常,aop 模式解决了这类问题引发重复代码大量积累,装饰器解决了些类问题 1:基础篇 import functools #采用functools.w 阅读全文
posted @ 2015-12-24 16:10 小泥巴2008 阅读(3231) 评论(0) 推荐(0)
摘要:引入线程包或者命名空间import threading 一:建立一个简单的线程程序 import time, threadingdef test(): print('thread %s is running...' % threading.current_thread().name) n = 0 w 阅读全文
posted @ 2015-11-24 14:49 小泥巴2008 阅读(479) 评论(0) 推荐(0)
摘要:该篇主要是针对面向对象的细讲,包括类的多重继承,方法的重写,析构函数,回收机制进行讲解 #该类主要是讲述python面象对象的一些特征,包括继承,方法的重写,多态,垃圾回收class person(object): name = '' age = '' def __init__(self,name, 阅读全文
posted @ 2015-11-17 01:35 小泥巴2008 阅读(224) 评论(0) 推荐(0)
摘要:定义了一个Animal类,该类包括了构造函数,私有方法,公有方法,静态方法,属性的方问等 双下划线"__"组成了私有成员的定义约束,其它情况则为公有成员 #_metaclass_=type # 确定使用新式类class Animal: address="acccd"; def __init__(se 阅读全文
posted @ 2015-11-17 01:26 小泥巴2008 阅读(268) 评论(0) 推荐(0)
摘要:#1. 打印字符串print ("His name is %s"%("Aviad"))#2.打印整数print ("He is %d years old"%(25))#3.打印浮点数print ("His height is %f m"%(1.83))#4.打印浮点数(指定保留小数点位数)print 阅读全文
posted @ 2015-11-13 18:20 小泥巴2008 阅读(357) 评论(0) 推荐(0)
摘要:python的数据很丰富,所以对于数据分析来讲, python是一种最合适的选择 下面讲述一下常见的数据结构,包括栈,队列,元组,字典,集合等,以及对这些数据结构进行操作 集合的遍历 #字典的遍历 补充: a = [[1, 2], [3, 4], [5, 6]]不使用任何循环,将上面的嵌套列表转换成 阅读全文
posted @ 2015-11-12 18:40 小泥巴2008 阅读(282) 评论(0) 推荐(0)
摘要:名词解释: 模块:一个程序文件 包:相当于一个类库,打包发布后相当于c#中的dll, 包中可包括若干个模块,比如main.py就是一个模块,对于test2文件下的所有模块组成一个包 对于一个包而言,注定是要被其它模块进行引用,所以需要一件初始化信息,比如包的路径,这些信息都是依赖包下的__init_ 阅读全文
posted @ 2015-11-12 15:30 小泥巴2008 阅读(4848) 评论(0) 推荐(0)
摘要:1 #方法的参数定义和默认参数的定义 2 def ask_ok(prompt, retries=4, complaint='Yes or no, please!'): 3 while True: 4 ok = input(prompt) 5 if ok in ('y', 'ye', 'yes'): 6 ... 阅读全文
posted @ 2015-11-09 16:50 小泥巴2008 阅读(558) 评论(0) 推荐(0)
摘要:#if statement number=int(input("please input a number")); if number20: print("is yound older"); else: print("any one else") #for statement _strlist=["fjfsjf'","apple","shje"]; for it... 阅读全文
posted @ 2015-11-05 01:46 小泥巴2008 阅读(287) 评论(0) 推荐(0)
摘要:#我的第一个python程序 print("hello world"); #多行字符串 print("""\ Usage: thingy [OPTIONS] -h Display this usage message -H hostname Hostname to connect to """); #转... 阅读全文
posted @ 2015-11-05 01:42 小泥巴2008 阅读(367) 评论(0) 推荐(0)
摘要:快速入门:十分钟学会Pythonhttp://python.jobbole.com/43922/python框架http://www.elias.cn/Python/HomePage#toc14[Python]多线程入门http://www.tuicool.com/articles/YvQRriip... 阅读全文
posted @ 2015-11-03 15:40 小泥巴2008 阅读(180) 评论(0) 推荐(0)