string literal or NoneType

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • menosaint@gmail.com

    string literal or NoneType

    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
Working...