Dealing with dictionary like strings

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Sat Jun 9 07:57:47 CEST 2007


En Fri, 08 Jun 2007 19:23:38 -0300, Mr SZ <sk8in_zombi at yahoo.com.au>  
escribió:

> I'm using the urllib module to fetch pages from the web.The returned  
> response is in the structure of a dictionary .For eg:
>
> {"":"","label": [
> ]
> ,"torrents": [
>
> ["F0666BDCCBFD01A52535759C044485E2E1CCE3C3",136,"AAA",1250164864,651,646185088,606208,0,0,0,-1,"",0,0,0,0,33564,7,342884352],
> ["46683EA1C950CB020DD6DD3007120EAB9966FA79",201,"tpg",4153995264,305,841170944,758087680,901,0,0,103109046,"",4,23,0,0,64080,2,2887053312]]
> ,"torrentc": "2001899868"}
>
> This response as we can see is not just like a dictionary but it's  
> values are in the  form of lists.Now,is there a way I can deal with this  
> string as a dictionary .I'm only interested in the value field of  
> torrents key which again is a list of lists.

See this Cookbook recipe: safe eval
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/364469

-- 
Gabriel Genellina




More information about the Python-list mailing list