-2

I have a folder defined "models". inside that, I have a python class(site.py)

I want to import that class to my main class.

I tried several ways but not working.

site.py

class site(object):
....

Main.py

def BuildATGSiteConfig():    
    a= site()
    return a
Dhaval Asodariya
  • 558
  • 5
  • 19
Ratha
  • 9,434
  • 17
  • 85
  • 163

1 Answers1

0

Create __init__.py [this way you declare that the directory is a package] file in directory, models. After that, in your main.py file, write from site import *, this will import every functions into main's scope. However, you can choose to publish/get only required functions form site. In such case. use from site import <function_name>. So, your main.py should look like

from site import *
from_site = site() #getting into local namespace.
from_site.site() #this is a function in site, and calling it in main.
Ajay2588
  • 527
  • 3
  • 6