2
I learned to import modules, but I don’t know how, for example, to create a class in a separate file and include it in the main program, how to do this?
2
I learned to import modules, but I don’t know how, for example, to create a class in a separate file and include it in the main program, how to do this?
5
Save the file in the same folder as the original file and you can import it without further problems.
arquivo1.py
class Classe:
def __init__():
....
arquivo2.py
from arquivo1 import Classe
obj = Classe()
......
Browser other questions tagged python
You are not signed in. Login or sign up in order to post.
It worked I was just kidding that I was only giving import file instead of from import file class
– Morais Vilson
It’s okay to just give import. But if you do
import arquivo1
will have to access your class doingobj = arquivo1.Classe()
– Arthur Gouveia