exec - What is the best way to call a Python script from another Python script? -


I have a test1.py name that is not in a module. It only has code that should run because of the script. There are no functions, classes, methods, etc. I have another script that runs as a service. I want to call test1.py from the script running as a service.

For example:

file test1.py

  print "I see an exam" print "! I'm not anything productive."  

file service

  # many things here test1.py # which is also in test1.py  

I know about a method that is opening the file, reading the material, and basically eval'ing it. I am assuming that there is a better way to do this. Or at least I hope so.

The usual way to do this is as follows. Def some_func (): printed 'test1, unproductive' if __name__ == '__main__': # test1.py script # executed as something something_func

Import ()

service.py

  import test1 def service_func (): print 'enjoy service' if __name__ == '__main__': # # Execute as feature.py script # service_func () test1.some_func ()  

Comments

Popular posts from this blog

c# - ListView onScroll event -

PHP - get image from byte array -

Linux Terminal Problem with Non-Canonical Terminal I/O app -