Created
August 26, 2016 07:14
-
-
Save kanchansrivastava/11d61484fd162c7223fe024c849c4cad to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def fetch_import_statement(): | |
my_imports = """ | |
import ast | |
import dill as pickle | |
import re | |
import pymongo | |
from datetime import datetime | |
import proton.blueprint | |
import proton.job_manager | |
import proton.language | |
import proton.plugins | |
import proton.template | |
import proton.ui | |
from proton import persistent | |
from proton.userdatabase import UserDatabase | |
from proton.util import dotdict | |
""" | |
astobj = ast.parse(my_imports) | |
packages_imported = [] | |
for node in ast.iter_child_nodes(astobj): | |
if isinstance(node, ast.Import): | |
for n in node.names: | |
packages_imported.append(n.name) | |
elif isinstance(node, ast.ImportFrom): | |
module_name = node.module | |
for n in node.names: | |
packages_imported.append('{0}.{1}'.format(module_name, n.name)) | |
return packages_imported |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment