Having trouble with relative imports

Echo oshecho at gmail.com
Tue Apr 10 13:41:09 EDT 2007


On 4/9/07, Echo <oshecho at gmail.com> wrote:
> Here is my setup:
> rpg
> -objects
> --__init__.py
> --gameobject.py
> --material.py
> -__init__.py
> -run_tests.py
> -stats.py
>
> the contents of run_test.py is:
> import objects as o
>
> the contents of objects/__init__.py is:
> from material import *
>
> in objects/material.py I have:
> from .gameobject import GameObject
> from ..stats import stats
>
> When I try to run run_tests.py, I get this traceback:
> (1:30:59 PM) OshEcho: echo at MobileEcho ~/projects/rpg $ python run_tests.py
> Traceback (most recent call last):
>   File "run_tests.py", line 4, in <module>
>     import objects as o
>   File "/home/echo/projects/rpg/objects/__init__.py", line 3, in <module>
>     from material import *
>   File "/home/echo/projects/rpg/objects/material.py", line 4, in <module>
>     from ..stats import stats
> ValueError: Attempted relative import beyond toplevel package
>
>
> Could someone point out to me what I am doing wrong?
> I'm running Python 2.5 on Gentoo
>
> --
> -Echo
>

Well, since I've gotten no answer and since that Python 2.5 doesn't
play well with some programs on Gentoo, I will be switch back to 2.4
for now.

-- 
-Echo



More information about the Python-list mailing list