2
Guys I’m having the following question.
I am studying importing modules and grabbed the following problem, my directory is with the following configuration:
Doubt 1 -> I want to import the operation modules to print and vice versa
Doubt 2 -> Import outro_módulo.py
for imprimir.py
or for one of the operating modules.
I’ve used that procedure:
import imp
arquivo, caminho, descrição = imp.find_module('módulo', ['/caminho/do/módulo/'])
nome_pro_módulo = imp.load_module('módulo', arquivo, caminho, descrição)
(worked but if changing machine can give conflict with respect to the way)
I used this one too:
import ..operacao import soma
But the following error occurs: Parent module '' not loaded, cannot perform relative import
Would anyone know where I’m going wrong?
In which file you are importing, in main.py?
– Woss
So in main.py I can import normally. The problem is qd I want to import the main.py module to print or if I want to import the soma.py module to print... these are the cases where the listed errors occur.
– Ficorrea
Is it possible to post code snippets? It is very confusing and difficult to understand what you are trying to do. Post an excerpt that worked in the desirable way and one that did not work, if possible.
– Woss
If you are inside main.py this import works normally: "from operation.subt import Subtracts"
– Ficorrea
Now if you are inside print.py and want to import this same module I used this path: "from .. import operation Subtrai", this error appears: Parent module 'not Loaded, cannot perform relative import
– Ficorrea
Take a look here: http://stackoverflow.com/questions/11536764/how-to-fix-attempted-relative-import-in-non-package-even-with-init-py
– Woss
Thanks, but I had already looked this Question and it didn’t work for what was said.
– Ficorrea