Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > automatic from module import * expansion

Reply
Thread Tools

automatic from module import * expansion

 
 
Keith Jackson
Guest
Posts: n/a
 
      03-13-2006
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
 
Reply With Quote
 
 
 
 
Diez B. Roggisch
Guest
Posts: n/a
 
      03-13-2006
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
 
Reply With Quote
 
 
 
 
astyonax
Guest
Posts: n/a
 
      03-13-2006
Sorry but I doesn't understand your need. If you need a ''dinamic''
import, you can use __import__(module)

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Why 'import module' will not import module.py but the directorymodule? Peng Yu Python 0 10-31-2009 11:51 PM
How to keep a module with the same name as a module it is importing from importing itself? plb Python 2 02-08-2005 03:14 PM
Handling import conflicts when module has the same name as a library module that it needs to import? plb Python 0 02-08-2005 01:08 PM
Handling import conflicts when module has the same name as a library module that it needs to import? plb Python 0 02-08-2005 01:01 PM
Automatic expansion of "inserted" JTree nodes dablick Java 0 12-12-2003 04:24 PM



Advertisments