0
Hello! I’m having a very recurring problem regarding "custom" module Imports in python 3 I’m doing a project of a very basic game thing myself and so far this is the structure of my project:
game/
__init__.py
main.py
classes/
__init__.py
player.py
media/
scripts/
__init__.py
dices.py
The problem comes when in the file "player.py" in the folder "classes" to do critical damage to the player it uses a function that is in the folder "functions/Dices.py"
If I try to use "from scripts import Dices" gives the "Import: cannot import name 'Dices' from 'scripts' (Unknown Location)"
If I use an import relative "from .. import Dices scripts" gives the "Import: attempted relative import with no known Parent package""
I have tried several ways including I saw answers in another discussion about which in the PEP 420 the archives init.py are no longer required (as far as I understand the comment) this is the link "/questions/371871/como-scri-um-arquivo-init-em-python-3"
I don’t understand anything else! If you can help me I will be very grateful!
try to put:
import ../functions/dice
– Codigo de Senior
From the syntax error "import .. /functions/Dice Syntaxerror: invalid syntax"
– Elias Oliveira
you use
linux
orwindows
? if it’swindows
I guess changing/
for\
works– Codigo de Senior
Use windows, in case it is to replace the "/" bar by double crase? "``"?
– Elias Oliveira
Wow, I didn’t realize the comment went wrong, sorry, subistitua
/
for \– Codigo de Senior
Also not import .. functions Dices Syntaxerror: invalid syntax The syntax error points to two points ".."
– Elias Oliveira
Let’s go continue this discussion in chat.
– Codigo de Senior
from ..scripts import dices
, whyscripts
, if the folder name isfunctions
?– Woss
@Eliasoliveira see if the answer to this question helps you: https://answall.com/questions/427965/import-em-directors-different-em-python3/427966#427966
– Lucas
@Woss was typing error (here in the thread) the folder name is scripts, mals by vacilo
– Elias Oliveira