分类目录

链接

2012 年 8 月
 12345
6789101112
13141516171819
20212223242526
2728293031  

近期文章

热门标签

新人福利,免费薅羊毛

asyncore实现异步SOCKET

最近一段时间用PYTHON写一个异步的SOCKET,刚开始用twisted框架,虽然可以在收到数据后使用异步方式处理会阻塞线程的工作,但始终无法实现一边发数据一边收数据,最后使用了asyncore,大概代码如下,如果中文注释乱码,请加#coding=utf-8 server端   # -*- coding: utf-8 -*- import socket import asyncore import threading MAX_REV = 4069 #负责接收client的连线 class AgentServer(asyncore.dispatcher): def __init__(self,port): #asyncore.dispatcher's init asyncore.dispatcher.__init__(self) #cli...

Python 暂无评论 阅读(3,166)

python 怎么添加中文注释

python中文注释乱码问题, python 添加中文注释 在文件头上写入: #coding=gbk 例如: #coding=gbk #mine,二进制相互转换 try: from binascii import a2b_qp, b2a_qp except ImportError: print u'没有找到 binascii 函数库' #二进制 ----> 可打印字符 file = open( 'd:\\tmp\\ua.ppt', 'rb' ) #读取二进制文件 data = file.read() odata = b2a_qp( data, 0, 0 ) ofile = open( 'd:\\tmp\\o_ua.txt', 'w' ) #以文本文件方式写入 ofile.write( odata ) ofile.close() file.close() #可打印字符 ---> 二进...

Redis 暂无评论 阅读(3,952)

python删除redis所有数据

>>> import redis >>> r = redis.Redis(host='localhost', port=6379, db=0) >>> r.set('foo', 'bar')   #或者写成 r['foo'] = 'bar' True >>> r.get('foo')    'bar' >>> r.delete('foo') True >>> r.dbsize()   #库里有多少key,多少条数据 0 >>> r['test']='OK!' >>> r.save()   #强行把数据库保存到硬盘。保存时阻塞 True -------------------------------- >>> r.flushdb()   #删除当前数据库的所有数据 True  >>&...

Redis 暂无评论 阅读(6,972)