Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!news-out.readnews.com!transit4.readnews.com!panix!gordon From: John Gordon Newsgroups: comp.lang.python Subject: Re: Send array back in result from urllib2.urlopen(request, postData) Date: Fri, 10 Jan 2014 22:53:19 +0000 (UTC) Organization: PANIX Public Access Internet and UNIX, NYC Lines: 57 Message-ID: References: NNTP-Posting-Host: panix1.panix.com X-Trace: reader1.panix.com 1389394399 10108 166.84.1.1 (10 Jan 2014 22:53:19 GMT) X-Complaints-To: abuse@panix.com NNTP-Posting-Date: Fri, 10 Jan 2014 22:53:19 +0000 (UTC) User-Agent: nn/6.7.3 Xref: csiph.com comp.lang.python:63671 In vanommen.robert@gmail.com writes: > result = urllib2.urlopen(request, postData) > para = result.read() > print para > the output is: > [null,null,null,null,null,"J"] > print para[1] > the output is: > n Probably because para is a string with the value '[null,null,null,null,null,"J"]' > How can I change the data back to an array? I've tried with json, but > that doesn't change anything. As far as I know, result.read() only returns text. If you want your results in some other format (like an array), you'll need to parse the string. This is a very simple (and ugly) way to do it, but it may give you a starting point: # open the url result = urllib2.urlopen(request, postData) # read the raw text results raw_text = result.read() # strip off the leading '[' and trailing ']' raw_text = raw_text[1:-1] # split raw_text into an array of strings text_array = raw_text.split(',') # declare a new list for storing the parsed items para = [] # process each string for item in text_array: if item == 'null': para.append(None) else: para.append(item) The python csv module might have a better way to do this; have a look. -- John Gordon Imagine what it must be like for a real medical doctor to gordon@panix.com watch 'House', or a real serial killer to watch 'Dexter'.