Lets say I have a function which I have defined:
def command("filename", function, error):
For 'function' I can input one of the following two functions:
def linear:
return x
def exponential:
return e**x
I want to save the figure under a name depended on the function used. So the name of figure will be something like this: filename_function.jpg
The command for this is plt.savefig(filename_+????+'.png')
How do I input the name of the specific function used into saved file?
So if my command is command("hello.txt", linear, error)
, then my save file should read hello_linear.png
.
Update: Thanks everyone. I am new to Python, and I guess I caught myself tied up in nonsense approaches to something that can be implemented very simply. The answer is function.__name__
exactly as written.