Electron microscopy
 
Call and then Run Your Own Functions and Modules in Different Python Files;
Python Run Another Python Script
- Integrated Circuits -
- An Online Book -
Integrated Circuits                                                                                   http://www.globalsino.com/ICs/        


=================================================================================

 

=====================================================

Method to run another script from one script:
          i) Use "import". This method with a proper design (refer to method iii)) can also be the most reliable (see an example below).
          ii) Use "execfile()",
          iii) exec(open()). This method with a proper design can also be the most reliable (see an example below).
          iv) Use "subprocess".

==============================================

Call a function, in a class in a Python script, from another script: code 1 and code 2:
         Code 1:
                    Escape characters
         Output after running Code 1:
                    Escape characters
         Code 2:
                    Escape characters
         Output after running Code 2:
                    Escape characters

=====================================================

Call and then run your own functions and modules in different Python files: code 1 and code 2:
         Code 1:
                 Call and then run your own functions and modules in different Python files
         Output from Code 1:
                Call and then run your own functions and modules in different Python files
         Code 2:
                 Call and then run your own functions and modules in different Python files
         Output from Code 2:
                Call and then run your own functions and modules in different Python files

============================================

Monitor specific new files and execute another file: code 1; and Create a .txt file with calling by another file: code 2:
    Code 1 (the lines marked in red below can avoid secondary excution of the Code 2 file trigered by the .txt file created by Code 2):
          Move files from one directory to another (the file must already exist)
     Code 2:
          Move files from one directory to another (the file must already exist)         
Before excuting Code 1:          
         Move files from one directory to another (the file must already exist)
After excuting Code 1:          
         Move files from one directory to another (the file must already exist)
After copying the two files in the red circle into the folder, the .txt file was generated by Code 2 since the file "ImagePool (12).jpg" was included:          
         Move files from one directory to another (the file must already exist) 
         Move files from one directory to another (the file must already exist)
In contrast, after copying the four files below into the folder, no .txt file was generated by Code 2 since the file "ImagePool (12).jpg" was not included:          
         Move files from one directory to another (the file must already exist) 
         Move files from one directory to another (the file must already exist)

=====================================================

Call and then run your own functions and modules in different Python files: code 1 and code 2:
         Code 1:
                 Call and then run your own functions and modules in different Python files
         Output from Code 1:
                Call and then run your own functions and modules in different Python files
         Code 2:
                 Call and then run your own functions and modules in different Python files
         Output from Code 2:
                Call and then run your own functions and modules in different Python files

=====================================================

Call and then run your own functions and modules in different Python files: code 1 and code 2:
         Code 1:
          Call and then run your own functions and modules in different Python files
         Code 2:
         Call and then run your own functions and modules in different Python files
Output:     
          Call and then run your own functions and modules in different Python files

=====================================================

The following shows the outputs when the two scripts, with __name__ == "__main__", run: Code 1 and Code 2:

     Code 1:
          __main__ to the __name__
     Output, which is the top level of Module 1 and the if output of Module 1 only:         
          __main__ to the __name__         
     Code 2:
          __main__ to the __name__
     Output, which are from the execution of the top level of Module 1, the else of Module 1, the executed function of Module 1, and the if output of Module 2:         
         __main__ to the __name__

=====================================================

Christmas card with turtle: main code with help of code 2:
         Christmas card with turtle
         Christmas card with turtle
         Christmas card with turtle
Code 2:          
         Christmas card with turtle
         Christmas card with turtle
Output:          
         Christmas card with turtle

=====================================================

=====================================================

Launch script from another script using subprocess.run or subprocess.call: Introduction

=====================================================

=====================================================


         

 

 

=================================================================================