Importing modules

Sébastien Boisgérault Sebastien.Boisgerault at gmail.com
Wed May 11 13:28:28 EDT 2005


qwwee... at yahoo.it wrote:
[...]
> In some cases there is a further complication: module importing
through
> an indirect mechanism, like: exec "from " + xxx + " import *".

Don't do that. Please ;). If you need too import some modules based
on the module name, stored in a string, consider the using __import__
(http://www.python.org/doc/2.4/lib/built-in-funcs.html). It's a bit
tricky but you may define your own help functions on top of it.

> A part the fact that I have not understood the "real" difference
> between import and from ... import (or also from... import *),


>>> a = exp(1.0) # does not work

>>> import math
>>> e = math.exp(1.0)# works
>>> e = exp(1.0)     # does not work

>>> from math import exp
>>> e = exp(1.0) # works

>>> from math import *
>>> e = exp(1.0)  # works
>>> o = sqrt(1.0) # works too

> is it
> possible to re-build the application in only one chunck?
> This is only to better understand the application's structure, in
order
> to implement a flow chart tool.

uh ?




More information about the Python-list mailing list