Import in Python

0

How do I import into Python being this class created by me?

Example: in java I create a connection class and I can make the amount of it in the stock class to be able to do the persistence in the bank, but I do not know how to do this in Python and I see examples on the internet but of modules, I have not yet seen of classes.

    
asked by anonymous 23.08.2017 / 02:06

1 answer

2

If the file containing the class is in the same directory as the file it will import,

from nome_do_arquivo import Nome_da_classe_nesse_arquivo

Example we have 2 files in the same place called myClasse.py and the other main.py

In myClasse.py we would have the following code:

class ClasseQueNaoFazNada():
    def nada():
        print("Nada")

And in the main.py file we will call the created class and run your method using this code:

from minhaClasse import ClasseQueNaoFazNada

ClasseQueNaoFazNada.nada()

So we can import and use a class created by us.

    
23.08.2017 / 02:38