Created
June 27, 2013 00:01
-
-
Save hogjonny/5872886 to your computer and use it in GitHub Desktop.
example for how you can return a functions name (as a string)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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