Hi, Here's what I get: print newText.keys() AttributeError: 'str' object has no attribute 'keys' Maybe my variable is the wrong type? I tried declaring it as an empty list but I can't seem to remember the correct way to do it newText = [] doesn't give an error, but it doesn't work either lol. thanks storm -- Follow me on Twitter: http://www.twitter.com/stormdragon2976 My blog, Thoughts of a Dragon: http://www.stormdragon.us/ What color dragon are you? http://quizfarm.com/quizzes/new/alustriel07/what-color-dragon-would-you-be/ On Wed, 2010-02-10 at 20:57 -0800, R Dinger wrote: > > > The error makes no sense to me. > > try looking at the keys of the dict first level: > > print newText.keys() > > do you get the first key? > > Richard > ----- Original Message ----- > From: Storm Dragon > To: programmingblind@xxxxxxxxxxxxx > Sent: Wednesday, February 10, 2010 7:35 PM > Subject: RE: Python discard extra information > > > > Hi, > when I did: > print newText["responseData"]["translatedText"] > I got this error: > Traceback (most recent call last): > File "translate.py", line 5, in <module> > print newText["responseData"][0] > TypeError: string indices must be integers, not str > when I changed both brackets to 0 I got { as the output > when I did it this way: > Print response["responseData"]: ["translatedText"] > I got a syntax error. > Thanks > Storm > > > > -- > Follow me on Twitter: > http://www.twitter.com/stormdragon2976 > My blog, Thoughts of a Dragon: > http://www.stormdragon.us/ > What color dragon are you? > > http://quizfarm.com/quizzes/new/alustriel07/what-color-dragon-would-you-be/ > > > > > On Wed, 2010-02-10 at 21:41 -0500, Ken Perry wrote: > > > > > > > > > > > Ah you beat me to it snicker I hate this email race game. > > > > > > > > Ken > > > > > > > > From:programmingblind-bounce@xxxxxxxxxxxxx > > [mailto:programmingblind-bounce@xxxxxxxxxxxxx] On Behalf Of > > R Dinger > > Sent: Wednesday, February 10, 2010 9:39 PM > > To: programmingblind@xxxxxxxxxxxxx > > Subject: Re: Python discard extra information > > > > > > > > > > > > Hi, > > > > > > > > > > > > > > Your output variable "newText" is a nested dictionary: > > > > > > {"responseData": {"translatedText":"Hola, ¿cómo estás > > hoy?"}, "responseDetails": null, "responseStatus": 200} > > > > > > So use the keys to get the translation: > > > > > > print newText["responseData"]["translatedText"] > > > > > > > > > > > > > > I assume the keys are always the same. > > > > > > > > > > > > > > Richard > > > > > > > > ----- Original Message ----- > > > > > > From: Storm Dragon > > > > > > To: programmingblind@xxxxxxxxxxxxx > > > > > > Sent: Wednesday, February 10, 2010 6:09 PM > > > > > > Subject: Re: Python discard extra information > > > > > > > > > > > > > > Hi, > > Here's the output: > > {"responseData": {"translatedText":"Hola, ¿cómo > > estás hoy?"}, "responseDetails": null, > > "responseStatus": 200} > > Here's the part I need in this version of the > > program, if the text variable changes, so does the > > required output: > > Hola, ¿cómo estás hoy? > > thanks > > Storm > > > > > > > > > > -- > > Follow me on Twitter: > > http://www.twitter.com/stormdragon2976 > > My blog, Thoughts of a Dragon: > > http://www.stormdragon.us/ > > What color dragon are you? > > > http://quizfarm.com/quizzes/new/alustriel07/what-color-dragon-would-you-be/ > > > > On Wed, 2010-02-10 at 17:50 -0800, R Dinger wrote: > > > > > > > > > > > > > > What other stuff are you getting? > > > > What exactly does your program output in the > > print statement? > > > > Richard > > > > > > ----- Original Message ----- > > > > From: Storm Dragon > > > > To: programmingblind@xxxxxxxxxxxxx > > > > Sent: Wednesday, February 10, 2010 > > 4:55 PM > > > > Subject: Python discard extra > > information > > > > > > > > Hi, > > I have written a small program to > > translate from english to another > > language, in this instance, Spanish. > > The problem is, it returns some > > other stuff that I don't need. How > > can I get just the translated text > > witout the other stuff? I only want > > to use standard libraries and keep > > it as short as possible. Thanks for > > the help. Here's the code: > > import urllib > > text = "hello, how are you today?" > > languageCode = 'es' > > newText = > > > urllib.urlopen("//ajax.googleapis.com/ajax/services/language/translate?v=1.0&q="; > + urllib.quote(text) + "&langpair=en|" + urllib.quote(languageCode)).read() > > print newText > > > > Thanks > > Storm > > > > > > > > > > -- > > Follow me on Twitter: > > http://www.twitter.com/stormdragon2976 > > My blog, Thoughts of a Dragon: > > http://www.stormdragon.us/ > > What color dragon are you? > > > http://quizfarm.com/quizzes/new/alustriel07/what-color-dragon-would-you-be/ > > > > > > > > > > > > > > > >