automatic from module import * expansion

Discussion in 'Python' started by Keith Jackson, Mar 13, 2006.

  1. 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
     
    Keith Jackson, Mar 13, 2006
    #1
    1. Advertising

  2. Keith Jackson wrote:

    > 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.


    No - and given that you could do

    --- module.py ---
    import random

    for i in xrange(random.randint(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
     
    Diez B. Roggisch, Mar 13, 2006
    #2
    1. Advertising

  3. Keith Jackson

    astyonax Guest

    Sorry but I doesn't understand your need. If you need a ''dinamic''
    import, you can use __import__(module)
     
    astyonax, Mar 13, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.

Share This Page