# How to import class from another file
Main
|-- animal_def.py
|-- file.py
# animal_def.py
class Animal:
def animalName(self,name):
print('This is {}'.format(name))
# file.py
from animal_def import Animal
ani = Animal()
im = ani.animalName('Tiger')
# How to import all classes from another folder
# animal_def.py
class Animal:
def animalName(self,name):
print('This is {}'.format(name))
class Plant:
def plantName(self,name):
print('this is {}'.format(name))
# file.py
from animal_def import *
ani = Animal()
bni = Plant()
im = ani.animalName('Tiger')
ik = bni.plantName('Neem')
# How to import all classes from another file
main
|-- module
|-- human_def.py
|-- run.py
main
|-- module
|-- human_def.py
|-- __init__.py
|-- run.py
# 1st create __init__.py file in from folder
# human_def.py
class Animal:
def animalName(self,name):
print('This is {}'.format(name))
#run.py
From module.human_def import Animal
ani = Animal()
im = ani.animalName('Tiger')
# How to import all classes from another file
main
|-- module
|-- module1
|-- human_def.py
|-- __init__.py
|-- run.py
#human_def.py
class Animal:
def animalName(self,name):
print('This is {}'.format(name))
#run.py
From module.module1.human_def import Animal
ani = Animal()
im = ani.animalName('Tiger')
Comments
Post a Comment