By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,235 Members | 1,107 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,235 IT Pros & Developers. It's quick & easy.

Why no string return?

P: n/a
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
Mar 12 '08 #1
Share this Question
Share on Google+
5 Replies


P: n/a
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
Mar 12 '08 #2

P: n/a
On Mar 12, 4:45 am, Adonis Vargas <adonis_var...@-Remove-This-
bellsouth.netwrote:
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')
Mar 12 '08 #3

P: n/a


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
Mar 12 '08 #4

P: n/a
On Mar 12, 5:10 am, Frank Millman <fr...@chagford.comwrote:
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.
Mar 12 '08 #5

P: n/a
>>>>gargonx <ga*****@gmail.com(g) wrote:
>gStill no return of string. The null testing is not really the deal.
gthat could be replaced with anything EG:
>gdef 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!"
>gdef SendMethod(request):
g xstring = "Some text"
g ReturnMethod(request, xstring)
>gSendMethod('random')
--
Piet van Oostrum <pi**@cs.uu.nl>
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email: pi**@vanoostrum.org
Mar 12 '08 #6

This discussion thread is closed

Replies have been disabled for this discussion.