Thanks Andi! On 8/7/09, Andi Albrecht <[email protected]> wrote: > > On Fri, Aug 7, 2009 at 6:54 AM, Jason > Salas<[email protected]> wrote: >> >> hi andi, >> >> the num and num2 arguments for the add() method are the input taken by >> the bot, if the user types in "?add num num2". (i ripped the command >> syntax used by the [email protected] bot. actually...now that >> you mention it, the only thing i could think of that would make it >> respond in that fashion would be that the user clicks the 'Done' >> button on the blip or presses Shift-Enter to submit the blip, which i >> guess would create a newline. is there a way to suppress that end of >> line? > > I don't know where the newline comes from. Maybe it's there for some > good reason. > However, I think the best thing you can do is to validate user input > (always an good idea :)), e.g. > > def add(num1, num2): > if not isinstance(num1, basestring) or not isinstance(num2, basestring): > # actually that shouldn't happen as you receive strings, anyway > respond with an error > num1 = num1.strip() > num2 = num2.strip() # this would remove any whitespace chars incl. new > lines > if not num1.isdigit() or not num2.isdigit(): > # both arguments must only contain digits, otherwise the user > input is invalid > res = int(num1)+int(num2) > ... > > Andi > >> >> >> >> On Fri, Aug 7, 2009 at 2:19 PM, Andi >> Albrecht<[email protected]> wrote: >>> >>> On Fri, Aug 7, 2009 at 12:46 AM, Jason >>> Salas<[email protected]> wrote: >>>> >>>> now that i'm in the office and have my code handy, here's the routine >>>> i'm using: >>>> >>>> def add(num,num2): >>>> sum = str(int(num) + int(num2)) >>>> return 'The sum of %s and %s is: %s' % (num,num2,sum) >>> >>> Given this code example, I think the only answer is that num2 is the >>> string "6\n".Where does num2 come from? >>> >>>> >>>> the output, as printed within a new blip and within my GAE logs, is: >>>> >>>> "The sum of 5 and 6\n is: 11" >>>> >>>> thoughts? >>>> >>>> On Fri, Aug 7, 2009 at 6:39 AM, Jason >>>> Salas<[email protected]> wrote: >>>>> I have this problem, too...I'm working in Python and doing string >>>>> interpolation and the outputted content that gets printed in a new >>>>> blip for some reason has a newline. I can't figure out why. >>>>> >>>>> On 8/6/09, jamz2010 <[email protected]> wrote: >>>>>> >>>>>> Hi all, >>>>>> >>>>>> I am having some issues with reading the last blip from my wavelet in >>>>>> my robot. I have used the line >>>>>> >>>>>> String sLastBlip = e.getBlip().getDocument().getText(); >>>>>> >>>>>> to get me the last blip that was added to the wave but it appears to >>>>>> be automatically adding a new line to the end of the wave. I have >>>>>> tried using >>>>>> >>>>>> sLastBlip = sLastBlip.replaceAll("\n", "n").replaceAll("\r", "r"); >>>>>> >>>>>> to remove all the new line characters from the string but this doesn't >>>>>> appear to work. I can use >>>>>> >>>>>> sLastBlip = sLastBlip.substring(0, sLastBlip.length()-1); >>>>>> >>>>>> to remove the last character from the string but if the user puts >>>>>> there own new line in it wont work. Does anyone know what character >>>>>> google wave uses for a new line? >>>>>> >>>>>> Thanks >>>>>> >>>>>> James >>>>>> >>>>>> >> >>>>>> >>>>> >>>> >>>> > >>>> >>> >>> > >>> >> >> > >> > > > >
--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Google App Engine" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en -~----------~----~----~----~------~----~------~--~---
