is it possible for me to get the line number which variable is defined in a different file.
for example:
file1.py
x = 5
mylist = [ 1, 2, 3]
file2.py
execfile("file1.py")
# TODO
# get line number of 'x' or 'mylist'
I assume each variable is defined only once but just in case what if they defined multiple times?
Thanks
A slightly improved version of Ashwini’s answer, using the
astmodule and not regular expressions is:And I think something similar can be used on already compiled objects…