10 2019 档案
摘要:import osimport multiprocessingdef copy_filename(q, filename, old_filename, new_filename): old_f = open(old_filename + '/' + filename, 'rb') content =
阅读全文
摘要:from multiprocessing import Poolimport os, time, randomdef worker(msg): t_start = time.time() print('{}开始执行,进程号为 {}'.format(msg, os.getpid())) # rando
阅读全文
摘要:import multiprocessingdef download_date(q): ''' 下载数据 ''' # 模拟从网上下载数据 data = [11, 22, 33, 44] # 向队列中写入数据 for temp in data: q.put(temp) print(' 已经下载完毕--
阅读全文
摘要:import multiprocessingimport timedef test1(): while True: print('1 ') time.sleep(1)def test2(): while True: print('2 ') time.sleep(1)def main(): p1 =
阅读全文
摘要:import threadingimport time# 定义一个全局变量g_num = 0def test1(num): global g_num for i in range(num): g_num += 1 print(' in test1 g_num={}'.format(g_num))de
阅读全文
摘要:import threadingimport time# 定义一个变量nums = [11, 22]def test1(nums): nums.append(33) print(' in test1 num={} '.format(nums))def test2(): print(' in test
阅读全文
摘要:num = 100nums = [11, 22]def test1(num): num += 1def test2(): global num num += 1def test3(nums): nums += [33]def test4(): global nums nums += [33]def
阅读全文
摘要:import threadingimport timedef test1(): for i in range(5): print(' test1 {}'.format(i)) time.sleep(1)def test2(): for i in range(10): print(' test2 {}
阅读全文
摘要:import socketdef main(): # 1. 创建套接字 tcp_server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # 2. 绑定本地信息 tcp_server_socket.bind(('', 1234
阅读全文
摘要:import socketdef main(): # 1 创建tcp套接字 tcp_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # 2 创建连接 tcp_socket.connect(('192.168.1.103', 801
阅读全文
摘要:import socketdef send_udp(udp_socket, dest_ip, dest_port): # 发送 send_data = input('请输入要发送的内容:') udp_socket.sendto(send_data.encode('utf-8'), (dest_ip,
阅读全文
摘要:import socketdef main(): # 1.创建套接字 udp_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # 2.绑定本地的相关信息,如果一个网络程序不绑定,则系统会随机分配 local_addr = ('',
阅读全文
摘要:import socketdef main(): # 创建一个udp套接字 udp_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # 可以使用套接字收发数据 #udp_socket.sendto(内容(必须是bytes类型), 对
阅读全文
摘要:1、re模块操作 # 导入 re模块 import re # 使用match 方法进行匹配操作 result = re.match(正则表达式,要匹配的字符串) # 如果上一步匹配到数据的话,可以使用group 方法来提取数据 result.group()2、匹配单个字符 . 匹配任意1个字符(除了
阅读全文
浙公网安备 33010602011771号