automatic from module import * expansion

K

Keith Jackson

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
 
D

Diez B. Roggisch

Keith said:
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
 
A

astyonax

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

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top