File size: 456 Bytes
4ec23ab
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import re

def find_imports(code):
    pattern = r'Python\.import_module\("([^"]*)"\)'
    matches = re.findall(pattern, code)
    return matches

if __name__ == "__main__":
    code = '''
    from python import Python
    Python.import_module("numpy")
    Python.import_module("pandas")
    Python.import_module("matplotlib")

    def main():
        print("hello world")
    '''

    print(find_imports(code))  # Output: ['numpy', 'pandas', 'matplotlib']