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

string literal or NoneType

P: n/a
hi all
i want to check a condition and if true should return a filename
string from a list.if the condition is false i am returning a
"" (string literal)..

retv=""
if somecondition:
retv=mylist[x]
....
return retv
The calling function will check the return value and print the
filename if it is not """.
in the calling function i can code
if returnval !="":
print "filename is:",returnval
else:
print "no filename found"

what i want to know is ,should i rewrite the if returnval !="" as

if returnval:
print "filename is:",returnval
else:
print "no filename found"

or is the way i coded the right way ? i am little confused here
Someone suggested that i make a variable retv None and if the
condition true then set retv as filename ,

retv=None
if somecondition:
retv=mylist[x]

....
return retv

which approach is correct..? can someone help please
vincent
Mar 15 '08 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.