how to run another file inside current file?

A

Avnesh Shakya

hi,
I want to run a another file inside a ached.add_cron_job(..). how is it possible, please help me, I have a file otherFile.py for execution inside current file.
I know it is very easy question but i m unable to get anything, please help me.
example --

import otherFile
from apscheduler.scheduler import Scheduler
sched = Scheduler()
sched.start()

def job_function():
# Can I here add that file for execution, Or can i add that file directly inside cron?

sched.add_cron_job(job_function, month='1-12', day='1-31', hour='0-23',minute='44-49')
 
T

Terry Jan Reedy

Hi,
It's better to specify version of python you work with.

Absolutely.


I know nothing
about python 3 but in python 2 you can do this with `exec`. Example:

Py 2 has execfile that does the above. Py 3 do as above except that exec
is a function.

with open('otherfile.py') as f:
exex(f)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,175
Latest member
Vinay Kumar_ Nevatia
Top