- 论坛徽章:
- 0
|
本帖最后由 caesarok 于 2011-11-22 11:28 编辑
如何最简便把下面表列转化为字典求教!- ['STAT pid 5719', 'STAT uptime 11814439', 'STAT time 1321929015', 'STAT version 1.2.6', 'STAT pointer_size 64', 'STAT rusage_user 2398.618354', 'STAT rusage_system 7011.354112', 'STAT curr_items 5247494', 'STAT total_items 40288174', 'STAT bytes 1613630635', 'STAT curr_connections 304', 'STAT total_connections 4771852', 'STAT connection_structures 386', 'STAT cmd_get 723291190', 'STAT cmd_set 40288174', 'STAT get_hits 598972008', 'STAT get_misses 124319182', 'STAT evictions 0', 'STAT bytes_read 34912490363', 'STAT bytes_written 181149584270', 'STAT limit_maxbytes 2147483648', 'STAT threads 1', 'END', '']
复制代码 上面为memcache stats的参数。
for i in range(len(get_response_data)):
print get_response_data.split(" ")
try:
d1[get_response_data.split(" ")[1]]=get_response_data.split(" ")[2]
except:
pass
或
def dc(x):
#print x
#print x.split(' ')
try:
d1[x.split(' ')[1]]=x.split(' ')[2]
except IndexError,args:
pass
return d1
for i in range(len(get_response_data)):
#print get_response_data.split(' ')[2]
dc(get_response_data)
print "get_his:%s"%d1['get_hits'],"get_misses:%s"%d1['get_misses'] |
|