Below you can see the function for extracting separate words from the text. Below you can see the text and code.
import re
text = '''
def function_cal(revenues_shops, surplus_margin, meadian_profit):
median_profit= revenues_shops* surplus_margin
return median_profit
def function_cal_new (revenues_stories_new, surplus_margin_new, meadian_profit):
median_profit= revenues_stories_new* surplus_margin_new
return median_profit
def function_cal_new1 (revenues_stories_new1, surplus_margin_new1, meadian_profit):
median_profit= revenues_stories_new1* surplus_margin_new1
return median_profit
'''
def extraction_variables(text):
splited_table1, splited_table2 = dict(), dict()
lines = text.split('\n')
for line in lines:
x = re.search(r"^def.*:$", line)
if x is not None:
values = x[0].split('def ')[1].split('(')
splited_table1 = values[0]
splited_table2 = values[1][:-2].split(', ')
return splited_table1, splited_table2
splited_table1, splited_table2 = extraction_variables(text)
splited_table1
splited_table2
This function extracts only one value from the first part of the text while other parts are not extracted. So can anybody help me how to solve this problem and store all words from text above in splited_table1 and splited_table2? For example splited_table1 need to contain function_cal, function_cal_new and function_cal_new1.