-2

I want to use a Python from a file in another folder.

The method is called writeToFiles. It is in a file called files.py which is in a folder called Utils.

The program that calls this method is in a folder called ratslam that also contains the Utils folder.

Borodin
  • 126,100
  • 9
  • 70
  • 144
Younès Raoui
  • 211
  • 5
  • 10
  • You need to ask a specific question and show the code that you've written. All you have provided is a statement of intent, which doesn't seem too difficult to achieve. What problem are you having exactly? – Borodin Sep 22 '17 at 19:07
  • I solved the problem. – Younès Raoui Sep 24 '17 at 15:00

2 Answers2

0

For importing modules from folder, you need to use:

from Utils.files import writeToFiles
Dharmesh Fumakiya
  • 2,276
  • 2
  • 11
  • 17
-1

Assuming your file structure is:

Utils/
    files.py

my_program.py

Create an empty file called init.py in Utils folder and root of the project.

Utils/
    __init__.py
    files.py
__init__.py
my_program.py

Then you should be able to add this line to the top of my_program.py

 from Utils.files import writeToFiles
townie
  • 302
  • 3
  • 9