473,327 Members | 2,065 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

Why no string return?

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
5 1251
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
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


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
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
>>>>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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Andrew | last post by:
I have written two classes : a String Class based on the book " C++ in 21 days " and a GenericIpClass listed below : file GenericStringClass.h // Generic String class
29
by: zoro | last post by:
Hi, I am new to C#, coming from Delphi. In Delphi, I am using a 3rd party string handling library that includes some very useful string functions, in particular I'm interested in BEFORE (return...
3
by: sernamar | last post by:
Hi, I have the following base class class UnitOfMeasure { public: //... std::string& GetName() {return _uomName;}; //... protected:
1
by: Sankalp | last post by:
Hi, I am using VB 2005. My application has many data bound controls. The connection is stored in the app.config file. I want the application to start with a default connection string and while...
3
by: jacob navia | last post by:
Abstract: Continuing the discussion about abstract data types, in this discussion group, a string collection data type is presented, patterned after the collection in C# and similar languages...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.