下面的方法在一个字符串中查找它是否有任何 python 方法。
def there_is_a_call( string ):
return string.find('(') > -1
def find_and_remove_functions( string , found_functions ):
if not there_is_a_call( string ):
print( found_functions )
return found_functions
else:
function_end = string.find('(')
function_string = string[:function_end][::-1]
if function_string.find('.') > -1 :
index = function_string.find('.')
elif function_string.find(' ') > -1:
index = function_string.find(' ')
else:
index = len(function_string) - 1
func_name = function_string[ : index + 1 ][::-1] + '()'
new_list = found_functions
new_list.append( func_name )
find_and_remove_functions( string[ function_end + 1: ], found_functions )
所以我尝试看看它是否有效,然后发生这种情况;
>>>> a = find_and_remove_functions( 'func() and some more()' , [] )
['func()', ' more()']
>>>> print(a)
None
为什么在found_functions
打印 do 时 return 语句不返回任何内容?