--- title: 'Function Extraction' --- Function Extraction === ## High level idea 1. Take source code 2. Run file namned "function_level.py" 3. Extract functions/classes 4. Save each extracted function/class separately as a .py file :::success function_level.py takes an argument (the path of the current directory i.e., where all the files are stored) ::: Code --- You can run the code as follows ```gherkin= Save all the files you want to run this script on in the current working directory run: python3 currentWorkingDirectory ``` Naming Convention --- The naming convention of the saved files is as follows: 1. If a source code (called test.py) is: ```gherkin= class abc: self.lock = _thread.lock() class xyz: self.lock = _thread.allocate_lock() def pqr(new, old): x = "hello" + old + new def stu(name): return type(sys)(name) ``` The code above will be split into **4** files, namely: 1. test_class_1.py (for class abc) 2. test_class_2.py (for class xyz) 3. test_function_1.py (for function pqr) 4. test_function_2.py (for function stu) Extra info/limitations --- 1. If you want to remove comments from the source code, uncomment line 73 2. This script does not handle nested functions/classes. A class of this structure is saved as **1** file: ```gherkin= class xyz: def __init__(self, name): self.lock = _thread.allocate_lock() class abc: def __exit__(self, name): self.lock = _thread.lock() ```