Closed berkerpeksag closed 9 years ago
Maybe something like
def finfo(codeobj): """Returns the file and line number of a code object. If the code object has a __file__ attribute (e.g. if it is a module), then the returned line number will be 0 """ fname = getattr(codeobj, '__file__', None) linenum = 0 if fname is None: func_code = codeobj.__code__ fname = func_code.co_filename linenum = func_code.co_firstlineno fname = fname.replace('.pyc', '.py') return fname, linenum
Yep, looks good!
I'll add it. I think I'll add a couple of things for anti8 as well.
Thanks, Pat
Thanks! Can you also add documentation for the new function?
I'll try to figure that out :)
Done in the code cleanup.
I think it would be useful to have https://github.com/berkerpeksag/astor/blob/master/astor/misc.py#L185-190 as an helper in astor.