Let's say I have a module with some code in it and I want to find the imported libraries for this module.
import os
import pandas as pd
import numpy as np
from os.path import basename, join
def export(df, folder):
"""some export thing (not really important)"""
f = join(folder, "test.csv")
df.to_csv(f)
return f
So this is just a dummy example. What the methods do aren't really important in this context of the question
From a previous question, I was able to get the import statements that import modules, not realizing that the from foo import bar
will not show.
[(x, y.__name__) for x,y in inspect.getmembers(sys.modules[__name__], inspect.ismodule)]
This will return a tuple:
[('inspect', 'inspect'), ('np', 'numpy'), ('os', 'os'), ('pd', 'pandas'), ('sys', 'sys')]
I can then take that list and if the tuple position 0 != position 1 then it's an import foo as f
situation. What is missing are situations where the from os.path impor basename, join
and situations where from os import path
. How do I include this types of imports?
Thanks