[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

Why no string return?

gargonx

3/12/2008 4:30:00 AM

Say i have the two methods:

def ReturnMethod(request, x):
if request is True:
return x
else: print "No String for you...False!"

def SendMethod(request):
xstring = "Some text"
ReturnMethod(request, xstring)

SendMethod(True)

Why does ReturnMethod not return the string x? I do believe it is
returning with a NoneType.
Any help would be greatly obliged

Thanks, Josh
5 Answers

Adonis Vargas

3/12/2008 4:46:00 AM

0

gargonx wrote:
> Say i have the two methods:
>
> def ReturnMethod(request, x):
> if request is True:
> return x
> else: print "No String for you...False!"
>
> def SendMethod(request):
> xstring = "Some text"
> ReturnMethod(request, xstring)
>
> SendMethod(True)
>
> Why does ReturnMethod not return the string x? I do believe it is
> returning with a NoneType.
> Any help would be greatly obliged
>
> Thanks, Josh

That is because request is bound a string (str) object. You are probably
testing for null so it should look like:

if request:
return x
else:
print "No String for you...False!"

Hope this helps.

Adonis

gargonx

3/12/2008 4:55:00 AM

0

On Mar 12, 4:45 am, Adonis Vargas <adonis_var...@-Remove-This-
bellsouth.net> wrote:
> gargonx wrote:
> > Say i have the two methods:
>
> > def ReturnMethod(request, x):
> > if request is True:
> > return x
> > else: print "No String for you...False!"
>
> > def SendMethod(request):
> > xstring = "Some text"
> > ReturnMethod(request, xstring)
>
> > SendMethod(True)
>
> > Why does ReturnMethod not return the string x? I do believe it is
> > returning with a NoneType.
> > Any help would be greatly obliged
>
> > Thanks, Josh
>
> That is because request is bound a string (str) object. You are probably
> testing for null so it should look like:
>
> if request:
> return x
> else:
> print "No String for you...False!"
>
> Hope this helps.
>
> Adonis

Still no return of string. The null testing is not really the deal.
that could be replaced with anything EG:

def ReturnMethod(request, x):
if request is 'random':
return x
else: print "No String for you...False!"

def SendMethod(request):
xstring = "Some text"
ReturnMethod(request, xstring)

SendMethod('random')

Frank Millman

3/12/2008 5:11:00 AM

0



gargonx wrote:
> Say i have the two methods:
>
> def ReturnMethod(request, x):
> if request is True:
> return x
> else: print "No String for you...False!"
>
> def SendMethod(request):
> xstring = "Some text"
> ReturnMethod(request, xstring)
>
> SendMethod(True)
>
> Why does ReturnMethod not return the string x? I do believe it is
> returning with a NoneType.
> Any help would be greatly obliged
>
> Thanks, Josh

ReturnMethod() is executed, but you do nothing with the result.

Try one of the following -

def SendMethod(request):
xstring = "Some text"
print ReturnMethod(request, xstring)

def SendMethod(request):
xstring = "Some text"
return ReturnMethod(request, xstring)

HTH

Frank Millman

gargonx

3/12/2008 5:18:00 AM

0

On Mar 12, 5:10 am, Frank Millman <fr...@chagford.com> wrote:
> gargonx wrote:
> > Say i have the two methods:
>
> > def ReturnMethod(request, x):
> > if request is True:
> > return x
> > else: print "No String for you...False!"
>
> > def SendMethod(request):
> > xstring = "Some text"
> > ReturnMethod(request, xstring)
>
> > SendMethod(True)
>
> > Why does ReturnMethod not return the string x? I do believe it is
> > returning with a NoneType.
> > Any help would be greatly obliged
>
> > Thanks, Josh
>
> ReturnMethod() is executed, but you do nothing with the result.
>
> Try one of the following -
>
> def SendMethod(request):
> xstring = "Some text"
> print ReturnMethod(request, xstring)
>
> def SendMethod(request):
> xstring = "Some text"
> return ReturnMethod(request, xstring)
>
> HTH
>
> Frank Millman

Thanks Frank the latter worked for my purpose.

Piet van Oostrum

3/12/2008 1:56:00 PM

0

>>>>> gargonx <gargonx@gmail.com> (g) wrote:

>g> Still no return of string. The null testing is not really the deal.
>g> that could be replaced with anything EG:

>g> def ReturnMethod(request, x):
>g> if request is 'random':

You shouldn't test with `is' but with `=='.

>g> return x
>g> else: print "No String for you...False!"

>g> def SendMethod(request):
>g> xstring = "Some text"
>g> ReturnMethod(request, xstring)

>g> SendMethod('random')

--
Piet van Oostrum <piet@cs.uu.nl>
URL: http://pietvano... [PGP 8DAE142BE17999C4]
Private email: piet@vanoostrum.org