Re: Python discard extra information

  • From: Jim Dunleavy <jim.dunleavy@xxxxxx>
  • To: programmingblind@xxxxxxxxxxxxx
  • Date: Thu, 11 Feb 2010 12:33:20 +0000

Hi Storm,

The result is json.
Use a json library to make a Python structure out of the string.
I think recent versions of Python (2.6?) have a json module as standard.
But the following works if you have the simplejson from Django:

from django.utils import simplejson

result = simplejson.loads(NewText)
print result['responseData']['translatedText']

--Jim

----- Original Message ----- 
From: Storm Dragon 
To: programmingblind@xxxxxxxxxxxxx 
Sent: Thursday, February 11, 2010 2:09 AM
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/




         

Other related posts: