【发布时间】:2015-07-01 00:09:59
【问题描述】:
我试图在 word_counter 函数中调用 cleanse 函数,但我不知道该怎么做。
这个程序的工作原理是一个字符串通过 cleanse 函数,字符串在 removed_characters 中的任何内容都被删除,然后小写。从那里,我需要在 word_counter 中“调用”已清理的消息,但这是我卡住的地方。我在下面尝试过。
#how to call this function?
def cleanse(message):
cleansed_message = ''
remove_characters = "+-=[]"
for i in message:
if i not in remove_characters:
cleansed_message = cleansed_message + i
cleansed_message = cleansed_message.lower()
return cleansed_message
def word_counter(message):
# I tried calling the cleansed message here
message = cleanse(message)
count = 0
for i in message:
count = len(message.split())
return count
【问题讨论】:
-
你说得很好。但是,您需要显式调用
word_counter函数 -
你是什么意思?来自主函数?
-
这是工作代码dpaste.com/1E3C7YN.. 以骗子的身份结束问题
-
当您说要“调用”已清理的消息时,不清楚您的意思。消息是一个字符串,字符串是不可调用的。该字符串是否可能代表您要调用的函数的名称?这是一个微妙但重要的区别。
-
在 word_counter 函数中,我的目标是观察修改后的字符串是否有意义?
标签: python string function call message