How to work with more than one python file?

Asked

Viewed 303 times

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?

1 answer

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()
......
  • It worked I was just kidding that I was only giving import file instead of from import file class

  • 2

    It’s okay to just give import. But if you do import arquivo1 will have to access your class doing obj = arquivo1.Classe()

Browser other questions tagged

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