Import module from another folder

4

I want to import a module that is in a folder that is the sister of the folder where I have the script, in which I want to import the other script, that is:

logic\ 
    board.py'
    mlogic.py
    player.py
gui\
    mgui.py

logic and gui are the slave folders, and I'm currently within mgui.py and would like to import the Board class from the board.py script. With PyCharm , I make this import from logic.board import Board , and it works, but not with IDLE , why? How can I resolve this? It seems strange that one works and the other does not ...

    
asked by anonymous 27.11.2014 / 18:52

1 answer

0

First, in both folders you must have a __init__.py file, after that, some module must be in a directory before the other, or you import both into a python in the root directory of both!

    
23.07.2015 / 00:31