Calling a Script from Another Script
Question:
How can one execute a script named "test1.py" from another script named "service.py" that is running as a service?
Answer:
To call a script from another script, the following approach is commonly employed:
test1.py:
def some_func(): print('in test 1, unproductive') if __name__ == '__main__': # test1.py executed as script # do something some_func()
service.py:
import test1 def service_func(): print('service func') if __name__ == '__main__': # service.py executed as script # do something service_func() test1.some_func()
This approach consists of the following steps:
The above is the detailed content of How Can I Execute One Python Script from Another, Especially When One is a Service?. For more information, please follow other related articles on the PHP Chinese website!