Sublime Forum

Extract names of imports

#1

Hello. I want to use the ST-API find_all() call to extract the names of imported libraries from a Python file in the view.

import wibble import weeble as wee from nee import shrubbery, water_effect from knights import lancelot as brave, arthur as king
I want to extract the library names, not their aliases (as).

I was planning to wrestle with the regex, but Iā€™m assuming someone has already done this before :smile:

I should also check that it is not commented out - either at the beginning of the line, or somewhere in the middle.

Andy.

0 Likes