0

I have a basic sort and search loop. At the end I want to thank the user and display the name of the function used. Is there a format call for doing this?

def arr_sort_binsearch(ar):

    item = 8

    ar.sort()
    l=0
    r=len(ar)-1

    while l<r:
        if (ar[l] + ar[r] == item):
            print("{} and {} is: {}".format(ar[l],ar[r],item))
            l += 1
            r -= 1
        elif (ar[l] + ar[r] < item):
            l += 1
        else:
            r -+ 1
    print("Thanks for using {}".format(name_of_function?)
oliver
  • 2,467
  • 3
  • 14
  • 29
  • 2
    If you had a function variable and wanted to know its definition name, you could use `f.__name__`. But if you mean the function you're in right now, why not just write `"Thanks for using arr_sort_binsearch"` ? – khelwood May 11 '17 at 21:34

1 Answers1

0

Here ya go:

How to get a function name as a string in Python?

Replace "name_of_function?" with:

arr_sort_binsearch.__name__
Community
  • 1
  • 1
William
  • 154
  • 9