newbie question structure of function

menosaint at gmail.com menosaint at gmail.com
Thu Mar 13 23:33:04 CET 2008


hi
I am  new to python programming..I would like to call a function that
returns an integer value  and a filename string  as a tuple.I coded it
like this below...I want to know if this can be coded more compactly
and efficiently..(i am from  java background and thus code often
becomes bulky ..)

def mycallerfunction():
    matchvalue,matchfilename=findmatchingfile()
    if not matchfilename:
        print "no match found"
        dosomething()

    else:
        print "match found:",matchfilename,"with matching
distance:",matchvalue
        dosomethingelse()


def findmatchingfile():
    # calculate matchdistance and matchfilename and return as tuple
    # if matchdistance found is not within a threshold then filename
    # may be "" (an empty string)
    ...
    ...
    resultname="""
    matchdistance,index=dosomecalculations()
    if (matchdistance < threshold):
       resultname=filenameslist[index]
    return (matchdistance,resultname)


if you can give some advice/suggestions it wd be great

thankx
-vincent



More information about the Python-list mailing list