
python
Alien_0x0111
这个作者很懒,什么都没留下…
展开
-
python上下文管理器的两种实现方式
# author : yang.cao # date : 2020.02.15 from contextlib import contextmanager class Context: def __init__(self, filename, mode): self.__filename = filename self.__mode = mode ...原创 2020-02-15 22:40:12 · 185 阅读 · 0 评论 -
python 中@property的用法实例
# author : yang.cao # date : 2020.02.13 class Goods: def __init__(self): self.original_price = 100 self.seal = 0.8 @property def price(self): return self.orig...原创 2020-02-14 00:40:02 · 164 阅读 · 0 评论 -
类对象实例对象类方法实例方法
实例方法不可以通过类来调用,类方法和静态方法可以被类调用 # author : yang.cao # date : 2020.02.13 class Cls: cls_arg = 10 def __init__(self): print("__init__") print(Cls.cls_arg) def item_fun(...原创 2020-02-13 23:33:25 · 774 阅读 · 0 评论 -
python中的继承测试代码
# author : yang.cao # date : 2020.02.12 class Parent: def __init__(self): print("Father") class Son1(Parent): def __init__(self): super().__init__() print("Son1"...原创 2020-02-13 01:07:36 · 212 阅读 · 0 评论 -
python中的深拷贝和浅拷贝
copy.copy()中如果拷贝的是列表等可修改对象,则会拷贝最上一层,如果拷贝的最上层是元组等不可修改对象,则只是拷贝了对象的引用: In [2]: a = [1, 2, 3] In [3]: b = copy.copy(a) In [4]: id(a) Out[4]: 140568059574600 In [5]: id(b) Out[5]: 140568059649992 In [...原创 2020-02-09 16:07:23 · 459 阅读 · 0 评论 -
python 单进程单线程长链接http server epoll实现
# author : yang.cao # date : 2020.02.07 import re import socket import select def server_client(client_socket, data): ret = None try: ret = re.match(r"[^/]*(/[^\s]*)", data.splitl...原创 2020-02-06 13:47:39 · 507 阅读 · 0 评论