Return a list of imported Python modules used in a script?

后端 未结 13 2255
深忆病人
深忆病人 2020-11-30 00:23

I am writing a program that categorizes a list of Python files by which modules they import. As such I need to scan the collection of .py files ad return a list of which mod

13条回答
  •  囚心锁ツ
    2020-11-30 01:04

    It's actually working quite good with

    print [key for key in locals().keys()
       if isinstance(locals()[key], type(sys)) and not key.startswith('__')]
    

提交回复
热议问题