2019年5月29日
摘要: tcp_server.py import socketserver class Myserver(socketserver.BaseRequestHandler): def handle(self): self.data = self.request.recv(1024).strip() # sel 阅读全文
posted @ 2019-05-29 23:02 lilyxiaoyy 阅读(557) 评论(0) 推荐(0) 编辑
摘要: ''' 编码的问题 python2解释器在加载.py文件中的代码时,会对内容进行编码(默认ascii),而python3对内容进行编码的默认为utf-8。 计算机: 早期,计算机是美国发明的,普及率不高,一般只是在美国使用,所以,最早的编码结构就是按照美国人的习惯来编码的。 对应数字+字母+特殊字符 阅读全文
posted @ 2019-05-29 21:07 lilyxiaoyy 阅读(1740) 评论(0) 推荐(0) 编辑
摘要: 服务端: 1.secret_key为bytes类型 2.random_bytes = os.urandom(n) 随机生成一个长度为n的random_bytes server.send(random_bytes)发送给客户端 3.hmac_bytes = hmac(secret_key, rando 阅读全文
posted @ 2019-05-29 19:10 lilyxiaoyy 阅读(383) 评论(0) 推荐(0) 编辑
摘要: hmac: hex-based message authentication code 哈希消息认证码 需要注意传入的key和message都是bytes类型,str类型需要首先编码为bytes。 # coding:utf-8 import hmac secret_key1 = b'This is 阅读全文
posted @ 2019-05-29 11:46 lilyxiaoyy 阅读(7035) 评论(0) 推荐(0) 编辑
摘要: # os.urandom(n)# Return a string of n random bytes suitable for cryptographic use.# This function returns random bytes from an OS-specific randomness 阅读全文
posted @ 2019-05-29 11:27 lilyxiaoyy 阅读(1007) 评论(0) 推荐(0) 编辑
摘要: ftp_server.py # coding:utf-8 import os import json import socket import struct class MyTcpServer(): address_family = socket.AF_INET # AF:address famil 阅读全文
posted @ 2019-05-29 00:41 lilyxiaoyy 阅读(708) 评论(0) 推荐(0) 编辑
  2019年5月27日
摘要: 最简单的FTP上次文件 # TCP服务端_server.py import socket import struct sk = socket.socket() # 创建socket对象 sk.bind(("127.0.0.1", 6666)) # 绑定IP和端口号 sk.listen() # 开启监 阅读全文
posted @ 2019-05-27 22:21 lilyxiaoyy 阅读(1315) 评论(0) 推荐(0) 编辑
摘要: 发送时: 先发报头长度(dict->json.dumps序列号(json字符串)->bytes->struct.pack打包) 再编码报头内容然后发送(dict->json字符串->bytes) 最后发真实内容 接收时: 先接收报头长度,用struct取出来(struct.unpack解包) 根据取 阅读全文
posted @ 2019-05-27 17:43 lilyxiaoyy 阅读(1094) 评论(0) 推荐(0) 编辑
摘要: struct模块是如何使用的呢? import struct msg = "我正在学习python的网络编程。" msg_bs = msg.encode("utf-8") # 将数据编码转为字节 res = struct.pack("i", len(msg_bs)) # 将字节数据的长度打包成固定长 阅读全文
posted @ 2019-05-27 13:47 lilyxiaoyy 阅读(1133) 评论(0) 推荐(0) 编辑
摘要: struck模块的使用:struct模块中最重要的两个函数是pack()打包, unpack()解包。 # coding:utf-8 import struct a = 18 bytes = struct.pack('i', a) print("%s pack后的长度:" % a, len(byte 阅读全文
posted @ 2019-05-27 12:31 lilyxiaoyy 阅读(2233) 评论(0) 推荐(0) 编辑
摘要: tcp_server.py # coding:utf-8 import socket import subprocess server = socket.socket() ip_port = ("127.0.0.1", 8001) server.bind(ip_port) server.listen 阅读全文
posted @ 2019-05-27 11:57 lilyxiaoyy 阅读(577) 评论(0) 推荐(0) 编辑
摘要: 一次性发送的数据量特别的大,导致对方无法接收那么大的数据时,会出现丢数据的情况哦。 # UDP服务端_server.py import socket import subprocess udp_server = socket.socket(type=socket.SOCK_DGRAM) ip_por 阅读全文
posted @ 2019-05-27 11:11 lilyxiaoyy 阅读(768) 评论(0) 推荐(0) 编辑
摘要: class Singleton(): __instance = None def __init__(self): print("我是init方法.") def __new__(cls): if not Singleton.__instance: Singleton.__instance = obje 阅读全文
posted @ 2019-05-27 09:59 lilyxiaoyy 阅读(1559) 评论(0) 推荐(0) 编辑
摘要: ''' 1、new方法和init方法执行的执行顺序? 答:先执行new方法,开辟内存,创建对象,再执行init ''' # class Person(): # def __init__(self, name, age): # self.name = name # self.age = age # p 阅读全文
posted @ 2019-05-27 09:44 lilyxiaoyy 阅读(194) 评论(0) 推荐(0) 编辑
  2019年5月26日
摘要: 发送数据时间间隔很短,数据也很小,会合到一起,产生粘包。 # TCP黏包现象_server.py import socket import time sk = socket.socket() sk.bind(("127.0.0.1", 8889)) sk.listen() conn, address 阅读全文
posted @ 2019-05-26 23:31 lilyxiaoyy 阅读(343) 评论(0) 推荐(0) 编辑
摘要: 客户端没有及时接收缓冲区的包,造成多个包接收(服务端发送了一段数据,客户端只收了一小部分,客户端下次再收的时候还是从缓冲区拿上次遗留的数据,产生粘包) tcp_stickybag_server.py # coding:utf-8 import socket import subprocess tcp 阅读全文
posted @ 2019-05-26 23:06 lilyxiaoyy 阅读(137) 评论(0) 推荐(0) 编辑
摘要: import subprocess cmd = input(">>>: ") res = subprocess.Popen( cmd, # 字符串指令,如dir 或 ipconfig等等 shell=True, # 使用shell,就相当于使用cmd窗口 stderr=subprocess.PIPE 阅读全文
posted @ 2019-05-26 22:20 lilyxiaoyy 阅读(1065) 评论(0) 推荐(0) 编辑
摘要: udp_server.py # coding:utf-8 import socket udp_server = socket.socket(type=socket.SOCK_DGRAM) # 创建socket对象,DGRAM:datagram 数据报文,UDP协议通信 ip_port = ("127 阅读全文
posted @ 2019-05-26 19:56 lilyxiaoyy 阅读(857) 评论(0) 推荐(0) 编辑
摘要: tcp_server.py # coding:utf-8 import socket server = socket.socket() # 创建socket对象 ip_port = ("127.0.0.1", 8001) # ip地址和端口号 server.bind(ip_port) # 绑定ip地 阅读全文
posted @ 2019-05-26 18:40 lilyxiaoyy 阅读(501) 评论(0) 推荐(0) 编辑
摘要: 端口+IP能够确定一台电脑上的某一个应用程序 # coding=utf-8 import socket server = socket.socket() # 相当于创建了一部电话 ip_port = ('127.0.0.1', 8001) # 创建一个电话卡, 是元组类型 server.bind(i 阅读全文
posted @ 2019-05-26 16:06 lilyxiaoyy 阅读(273) 评论(0) 推荐(0) 编辑
  2019年5月24日
摘要: hasattr(obj, str) 判断obj对象中是否有str成员 getattr(obj, str) 从obj对象中获取str成员 setattr(obj, str, value) 把obj对象中的str设置为value delattr(obj, str) 从obj对象中删除str成员 以上方法 阅读全文
posted @ 2019-05-24 11:37 lilyxiaoyy 阅读(452) 评论(0) 推荐(0) 编辑
  2019年5月23日
摘要: ''' 1、简述类、对象、实例化、实例是分别是什么? 类是具有相同特征和功能的一类事物. 对象是通过类来创建的具体的个体. 每个对象都有自己的独立的名称空间. 对象和实例是具体的某一事物. 实例化是对象/实例创建的过程. ''' '''' 2、请简述面向对象三大特性? (1).封装: 隐藏对象的属性 阅读全文
posted @ 2019-05-23 17:09 lilyxiaoyy 阅读(282) 评论(0) 推荐(0) 编辑
摘要: 1. 作业 2. 模块 一个py文件 导入过程: 1. 判断模块在内存是否已经存在 2. 如果有, 直接引入使用 3. 如果没有, 创建一个名称空间. 在名称空间中执行模块中的代码 4. 导入模块的名字 导入模块的顺序: 1. 内置 2. 第三方 3. 自定义 __name__ __main__ 执 阅读全文
posted @ 2019-05-23 17:08 lilyxiaoyy 阅读(111) 评论(0) 推荐(0) 编辑
  2019年5月12日
摘要: 1. 上次课内容回顾 模块 1. import xxxx 2. from xxxx import xxxx random randint uniform sample choice shuffle Collections Counter defaultdict deque 双向队列 queue 队列 阅读全文
posted @ 2019-05-12 09:57 lilyxiaoyy 阅读(149) 评论(0) 推荐(0) 编辑
  2019年5月11日
摘要: ''' 作业 爬去dytt 2019新片精品 -> 把所有电影的名字, 主演, 下载链接. 放在一个json文件里 { {"main_people": ["井柏然", "张一山"], "name": xxxx, "url":}, {}, {} } 要求: 代码合理性 ''' from urllib. 阅读全文
posted @ 2019-05-11 11:42 lilyxiaoyy 阅读(12565) 评论(0) 推荐(0) 编辑
摘要: ''' 1、计算两个格式化时间之间差了多少年月日时分秒 ''' # import time # # def diff_date(date_str1, date_str2): #方法一 # diff_second = int(abs(time.mktime(time.strptime(date_str 阅读全文
posted @ 2019-05-11 11:41 lilyxiaoyy 阅读(211) 评论(0) 推荐(0) 编辑
  2019年4月30日
摘要: 正则表达式 规定一个格式. 匹配字符串用的 普通字符, 平时用到的一些文字信息 元字符(重点) 1 . 除了换行符以外的所有内容 2 \d 数字 3 \w 匹配数字, 字母, 下划线 4 \n 换行 5 \s 匹配所有的空白 6 ^ 字符串的开始 7 $ 字符串的结束 8 [] 字符组 9 [^.. 阅读全文
posted @ 2019-04-30 11:35 lilyxiaoyy 阅读(131) 评论(0) 推荐(0) 编辑
摘要: import sys """所有和python解释器相关的都在sys模块""" sys.argv # 命令行参数List,第一个元素是程序本身路径 sys.exit(n) # 退出程序,正常退出时exit(0),错误退出sys.exit(1) sys.version # 获取Python解释程序的版 阅读全文
posted @ 2019-04-30 11:33 lilyxiaoyy 阅读(165) 评论(0) 推荐(0) 编辑
摘要: import os """目录操作""" os.makedirs("a/b/c") # 创建多级目录(推荐使用) os.removedirs("a/b/c") # 删除多级目录(不推荐使用) os.mkdir("aa") # 创建一级目录 os.rmdir("aa") # 删除一层目录 os.lis 阅读全文
posted @ 2019-04-30 11:25 lilyxiaoyy 阅读(194) 评论(0) 推荐(0) 编辑
  2019年4月29日
摘要: '''栈stack 先进后出FILO (first in last out)''' lst = [] lst.append("张一山") lst.append("杨紫") lst.append("周冬雨") ret = lst.pop() print(ret) ret = lst.pop() pri 阅读全文
posted @ 2019-04-29 18:04 lilyxiaoyy 阅读(4109) 评论(0) 推荐(0) 编辑
摘要: from collections import defaultdict '''默认值字典''' d = defaultdict(lambda: 123) print(d) print(type(d)) print('__iter__' in dir(d)) print('__next__' in d 阅读全文
posted @ 2019-04-29 17:26 lilyxiaoyy 阅读(1124) 评论(0) 推荐(0) 编辑
摘要: from collections import Counter c = Counter("周周周周都方法及") print(c) print(type(c)) print('__iter__' in dir(c)) print('__next__' in dir(c)) print('items' 阅读全文
posted @ 2019-04-29 16:57 lilyxiaoyy 阅读(2081) 评论(0) 推荐(0) 编辑
摘要: import json """将python的字典和列表转化为json字符串。json是前后端交互的枢纽""" dic = {'name': '莉莉', 'age':18} str_json = json.dumps(dic, ensure_ascii=False) # 将python中的字典转换为 阅读全文
posted @ 2019-04-29 14:15 lilyxiaoyy 阅读(1314) 评论(0) 推荐(0) 编辑
摘要: import random '''random随机数模块''' # 生成一个0到1的随机小数,不常用 print(random.random()) print(type(random.random())) 0.591104288833299 <class 'float'> import random 阅读全文
posted @ 2019-04-29 14:00 lilyxiaoyy 阅读(487) 评论(1) 推荐(1) 编辑
摘要: import time # strftime获取当前系统格式化时间,%X和%H:%M:%S相等 print(time.strftime("%Y-%m-%d %H:%M:%S")) print(time.strftime("%Y-%m-%d %X")) print(type(time.strftime 阅读全文
posted @ 2019-04-29 11:23 lilyxiaoyy 阅读(255) 评论(0) 推荐(0) 编辑
  2019年4月28日
摘要: import pickle """将对象转化为硬盘能识别的bytes的过程被称为序列号。pickle可以把任意python类型的数据转化为字节"""print(pickle.dumps("中")) print(type(pickle.dumps("中"))) print(pickle.dumps([ 阅读全文
posted @ 2019-04-28 14:24 lilyxiaoyy 阅读(966) 评论(0) 推荐(0) 编辑
摘要: 1. 上周内容回顾 1. 闭包: 内层函数对外层函数变量的使用 def outer(): a = 10 def inner(): print(a) return inner ret = outer() ret() ret() ret() ret() 2. 迭代器 dir() 查看某变量能执行哪些操作 阅读全文
posted @ 2019-04-28 11:44 lilyxiaoyy 阅读(211) 评论(0) 推荐(0) 编辑
摘要: ''' 二分法查找 有序列表 掐头去尾取中间 查找列表中xx在不在列表中,在,则返回索引值 ''' # lst = [1, 4, 6, 8, 9, 21, 23, 26, 35, 48, 49, 54, 67, 89, 99] #使用in判断,不使用二分法 # n = 49 # for i, v i 阅读全文
posted @ 2019-04-28 11:24 lilyxiaoyy 阅读(845) 评论(0) 推荐(0) 编辑
摘要: 内置函数导图:https://www.processon.com/view/link/5b4ee15be4b0edb750de96ac#map '''python中的内置函数分类 1、输入输出:print、input 需要注意的是input输入的数据是字符串类型。 ''' print("Hello 阅读全文
posted @ 2019-04-28 10:28 lilyxiaoyy 阅读(227) 评论(0) 推荐(0) 编辑
  2019年4月27日
摘要: ''' 作业题目: 模拟博客园登录 作业需求: 1),启动程序,首页面应该显示成如下格式: 欢迎来到博客园首页 1:请登录 2:请注册 3:文章页面 4:日记页面 5:评论页面 6:收藏页面 7:注销 8:退出程序 2),用户输入选项,3~6选项必须在用户登录成功之后,才能访问成功。 3),用户选择 阅读全文
posted @ 2019-04-27 18:26 lilyxiaoyy 阅读(308) 评论(0) 推荐(0) 编辑

返回
顶部