Let's suppose we have the following Python script in my_script.py
file:
import numpy as np
import matplotlib.pyplot as plt
a = np.linspace(1, 10, 100)
plt.figure()
plt.plot(a, a**2)
plt.show()
Is there a way to tell programmatically if (and in which line on the script) the function plot
from the module matplotlib.pyplot
is being called? [so that the answer will be something like 'line 7, column 1']
Ultimately, what I would like to do is to come up with a Python code that could locate, in another (given) Python script file, the position(s) in the file where a specific function from a specific module is being called.
I'm sure there are some Python tools for this, it is only that it's been hard for me to find anything on the web because I don't know the jargon for this kind of operation (introspection?) and basically don't know how to look for it. I guess something like modulefinder
might work, but I have had no experience working with it and figure some of you guys might point me in the right direction.
Sorry for the bad english (not my native language). Thanks in advance for your help.