automatic from module import * expansion

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Keith Jackson

    #1

    automatic from module import * expansion

    Does anybody know of a tool that will take a module as input, look for
    any wildcard imports, and then identify what symbols in the module come
    from which wildcard import? It could then expand out the from module
    import * to from module import foo, bar. It might need to ask the user
    on this, since they might want the wildcard import for something
    special, but it would still be *much* nicer then expanding the imports
    out by hand.

    Apologies ahead of time if I've missed something obvious. I did spend
    some quality time with google, and couldn't find anything.
    cheers,
    --keith
  • Diez B. Roggisch

    #2
    Re: automatic from module import * expansion

    Keith Jackson wrote:
    [color=blue]
    > Does anybody know of a tool that will take a module as input, look for
    > any wildcard imports, and then identify what symbols in the module come
    > from which wildcard import? It could then expand out the from module
    > import * to from module import foo, bar. It might need to ask the user
    > on this, since they might want the wildcard import for something
    > special, but it would still be *much* nicer then expanding the imports
    > out by hand.
    >
    > Apologies ahead of time if I've missed something obvious. I did spend
    > some quality time with google, and couldn't find anything.[/color]

    No - and given that you could do

    --- module.py ---
    import random

    for i in xrange(random.r andint(10, 100)):
    globals()["FOO%i" % i] = "hallo"

    --- module.py ---

    there is not a chance of such a tool being more than a heuristic. Such
    things only work in a static typed world where you know the number of
    declarations.

    Diez

    Comment

    • astyonax

      #3
      Re: automatic from module import * expansion

      Sorry but I doesn't understand your need. If you need a ''dinamic''
      import, you can use __import__(modu le)

      Comment

      Working...