#1
  1. JavaScript is not spelt java
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2011
    Location
    Landan, England
    Posts
    743
    Rep Power
    167

    Extract from and import


    Hello. From a Python file I want to extract the imported library names. For example:

    Code:
    import sublime, sublime_plugin as sp
    from os import path as eric
    import os, datetime, tempfile, desktop    # some comment
    I want to collect sublime, sublime_plugin etc.. I might also want to collect the (as) aliases, but initially I'm just interested in the library names.

    I can assume that from or import are at the beginning of the lines, and they may be followed by eol, whitespace or # (indicating a comment).

    This may be straight-forward
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2016
    Posts
    21
    Rep Power
    0
    The names of library:

    Code:
    ^import (\w+)[, ]+([^#, ]+)|^from (\w+)
    with /g/m

IMN logo majestic logo threadwatch logo seochat tools logo