How to debug python in Visual Studio Code

Asked

Viewed 416 times

1

I have the following structure and folders and files:

DebugTeste
         |--br
             |--com
                  |--empresa
                           |--implementacao
                           |              |--__init__.py 
                           |              |--Ola.py
                           |
                           |--testes
                                   |--testeOlaMundo

__init__.py code:

# __init__.py
from .Ola import OlaMundo

Ola.py code:

class OlaMundo():
    def OlaMundoMensagem():
        return "Olá Mundo"

testeOlaMundo.py code:

from br.com.empresa.implementacao.Ola import OlaMundo

OlaTexto = OlaMundo.OlaMundoMensagem()

print(OlaTexto)

When I go thresh the testeOlaMundo by Visual Studio Code, the following error occurs,

Exception has occurred: ModuleNotFoundError No nodule named br' 
  • This import will only work if you install the module. You can do something like from ..implementacao.Ola import OlaMundo, indicating the relative import.

  • Download this extension, follow this tutorial, for more information on python in visual studio look this page, I suggest you carefully read each step of both the extension and tutorial pages so that no errors occur.

  • Thanks for the help, I did the recommended, but I got "attempted relative import with no known Parent package". To run correctly I created a main.py file on the same level as the br folder, in it I call the testOlaMundo.py file

  • Out of curiosity, why are you creating modules inside so many packages? This seems to be the standard of Java or Go, but in Python there is no reason to do so.

  • Anderson, I’m doing some tests, if I go to work with a big project I’ll have to create packages to organize things

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.