Having trouble with relative imports

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Echo

    #1

    Having trouble with relative imports

    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@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
Working...