Skip to content Skip to sidebar Skip to footer

Extract Functions From Python File And Write Them To Other Files

i have writted a python file with a lot of functions and i decided i want to split all of them to diffrent files with their names and with the same imports. the code looks somethin

Solution 1:

Make new script "split.py" or something. This script should do:

1) Open the above file as string. How do I read a text file into a string variable in Python

2) Split with argument " def ". Now you will have list of strings, lets call that list L.

3) Ignore first element in L and iterate over all others.

4) For each that string, lets call it S, open new file and write into it:

import....

classTestExtractors(unittest.TestCase):

Below that write string S.

Let me know if I need to clarify any step.

Post a Comment for "Extract Functions From Python File And Write Them To Other Files"