string literal or NoneType

menosaint at gmail.com menosaint at gmail.com
Sat Mar 15 11:27:32 EDT 2008


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



More information about the Python-list mailing list