Skip to content

Instantly share code, notes, and snippets.

@hogjonny
Created June 27, 2013 00:01
Show Gist options
  • Save hogjonny/5872886 to your computer and use it in GitHub Desktop.
Save hogjonny/5872886 to your computer and use it in GitHub Desktop.
example for how you can return a functions name (as a string)
def foo():
# a func can just make a call to itself and fetch the name
funcName = foo.__name__
# print it
print 'Internal: {0}'.format(funcName)
# return it
return funcName
# you can fetch the name externally
fooName = foo.__name__
print 'The name of {0} as fetched: {0}'.format(fooName)
# print what name foo returned in this example
whatIsTheName = foo()
print 'The name foo returned is: {0}'.format(whatIsTheName)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment