初学python后写的第一个小程序:
1 import re, threading, telnetlib, time 2 3 def out_put(t): 4 while True: 5 time.sleep(0.1) 6 rbuff = t.read_very_eager().decode('gb18030') 7 if rbuff: 8 pbuff = re.sub('[[0-9;]*[mADK]', '', rbuff) 9 if pbuff:10 print(pbuff)11 def in_put(t):12 while True:13 a = input("input: ")14 t.write(a.encode('gb18030') + b'\n')15 16 t = telnetlib.Telnet("pkuxkx.net", 8080)17 t1 = threading.Thread(target = out_put, args = (t,))18 t2 = threading.Thread(target = in_put, args = (t,))19 t1.start()20 t2.start()