I have Workflow.py file containing following function:
class Workflow:
def Validation(self):
return print ("Validation Process Started..")
I have another file Cron.py.
import schedule
import time
from Workflow import Validation
class Cron:
def my_job(self):
print('Foo')
Workflow.Validation()
def Start(self):
schedule.every(2).to(4).seconds.do(self.my_job)
while 1:
schedule.run_pending()
time.sleep(1)
A = Cron()
A.Start()
I am trying to call Validation() function present in Workflow.py from Cron.py file. Both of these files are places in same folder. But, the code is giving following exception:
Traceback (most recent call last):
File "cron.py", line 3, in <module>
from Workflow import Validation
ImportError: cannot import name 'Validation'
Please can anyone help on resolving this error.
from Workflow import Workflowwhich should fix itValidationis not a top level function. It's a class method. Change your import tofrom Workflow import Workflow