0

Current File Structure

Game/
    __init__.py
    main.py

    Physics/
       __init__.py
       utils.py

    Models/
       __init__.py
       player.py

File Contents of Game/__init__.py

from Models import player

File Contents of Game/Physics/__init__.py

from ..Models import player

File Contents of Game/Models/__init__.py

class PlayerModel(object):
    def __init__(self):
        object.__init__(self)

File Contents of Game/Physics/utils.py -> Where error is occuring with No Module named Game

from Game import player # here is error?

def model_weapon_damage(weapon_model: player.Weapon):
    return weapon_model.base_damage

def model_armor_negation(armor_model: player.Armor, weapon_model: player.Weapon):
    weapon_damage = model_weapon_damage(weapon_model)

I have tried looking up how to import using the file structure, but i can't follow. i am trying to give Game access to everything and have other class files be able to use the imports

  • cant you just use your import like you do in the init `from ..Models import player` – Chris Doyle Mar 02 '20 at 19:24
  • 1
    Does this answer your question? [Importing from a relative path in Python](https://stackoverflow.com/questions/7505988/importing-from-a-relative-path-in-python) – Chris Doyle Mar 02 '20 at 19:24

1 Answers1

0

Make sure you are referencing everything from the project root (Game).

from Game.Models import player

The __init__.py files can be empty. They just tell python that it is a package directory.