On 12/02/2010, Storm Dragon <stormdragon2976@xxxxxxxxx> wrote: > Hi, > I have tested quite a bit and so far it works. The fortunate thing is > that if the translation happens, the string always contains the same > info at the beginning and end, so the same slice will work each time. I > test for the status to be "200}" and if that is the case, everything > worked so I can make the translation. It may not be the prettiest thing > in the world, but it seems to work ok for now. > I'll have to do a php version soon, and I will most likely go with the > json method with it. > 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 Thu, 2010-02-11 at 16:43 -0800, R Dinger wrote: > >> >> >> Hi Storm and Jim, >> >> Storm, your method may not always work as you rely on character >> positions for a specific string. >> >> IN Python 2.6 the json library is available via: >> import json >> >> Then change Jim's code to use json.loads and everything will work as >> Jim showed it. >> >> Richard >> ----- Original Message ----- >> From: Storm Dragon >> To: programmingblind@xxxxxxxxxxxxx >> Sent: Thursday, February 11, 2010 7:51 AM >> Subject: Re: Python discard extra information >> >> >> >> Hi, >> I tested the method you gave me and unfortunately I didn't >> have the django.utils library installed by default. Your >> solution did help me though, because for some reasn the word >> string stuck out at me this time. Why it didn't before, why I >> refused to treat the result like a string in the first place, >> I will never know. But finally, your message made it click. >> So, I treated it like a string, a string in which the >> beginning and the end, assuming all goes well, are the same. >> Now, I have what I needed, the result without having to >> install non-default libraries, at least I hope anyway. Here's >> the program in it's working state: >> 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() >> newText = newText[36:-51] >> print newText >> >> thanks so much everyone for all the help >> 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 Thu, 2010-02-11 at 12:33 +0000, Jim Dunleavy wrote: >> >> > 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/ >> > > >> > > >> > > >> > > >> > > >> > > > hi there, can anyone let me know how can i remove myself from the list? thanks __________ View the list's information and change your settings at //www.freelists.org/list/programmingblind