How do I import packages from a subfolder to a folder? In python

0

Suppose that each folder / package already has its respective init .py

If I have this composition:

-Carpeta Padre
|   archivo1.py
|   
|   Carpeta Hija
|     | 
      |archivo2.py
|     |_____________
|
|____________________

I would like to import from file2.py the things from file1.py, obviously when I do from Folderpadre import file1.py it does not work.

If it's not too much trouble they could explain to me what the "." and ".." because I've seen in some places that they make from .. import Xcosa, I tried it and it did not work either. Use python 2.7

Thank you very much

    
asked by Aaron David 15.03.2018 в 21:11
source

1 answer

1

With this you import the entire file file2, you must do it without it .py

 from carpeta_hija import archivo2

And to import the modules of file 2, to call things from file 2 you must indicate it at the beginning.

archivo2.modulo()
    
answered by 25.04.2018 в 17:23