Module Conflicts

Ivan Illarionov ivan.illarionov at gmail.com
Thu Apr 10 16:41:29 EDT 2008


On Apr 11, 12:31 am, Ivan Illarionov <ivan.illario... at gmail.com>
wrote:
> On Apr 10, 2:33 am, Jose <jfgome... at gmail.com> wrote:
>
> > I have a module named math.py in a package with some class
> > definitions.  I am trying to import the standard python math module
> > inside of math.py but It seems to be importing itself.  Is there any
> > way around this problem without renaming my math.py file?
>
> Yes, if you are using Python 2.5
>
> from __future__ import absolute import
>
> after this `import math` will always import standard math module and
> `from . import math` will import your module.
>
> --
> Ivan

I should say `from __future__ import absolute_import`

And it's relatively easy to do in earlier versions too:
create subdirectory `stdmath` with one `__init__.py` file with one
line `import math` and than use `from stdmath import math`.
and than use



More information about the Python-list mailing list