-2
如何在类中使用'默认'方法,例如:string.lower()
?如何在类中应用python方法?
这是我的错误:
result = text.lower.replace(string.punctuation, ' ').split(' ')
AttributeError: MyClass instance has no attribute 'lower'
如何在类中使用'默认'方法,例如:string.lower()
?如何在类中应用python方法?
这是我的错误:
result = text.lower.replace(string.punctuation, ' ').split(' ')
AttributeError: MyClass instance has no attribute 'lower'
你缺少一个更一套()
result = text.lower().replace(string.punctuation, ' ').split(' ')
^
()
在lower
方法缺失。
a.lower
将返回函数对象。
例如
>>> a = "ABCf"
>>> a.lower
<built-in method lower of str object at 0xb7047ac0>
>>> a.lower()
'abcf'
我添加了大括号,但仍然出现错误。结果='text.lower()。replace(string.punctuation,'').split('') AttributeError:MyClass实例没有属性'lower'' – Omicron 2015-03-02 14:47:10
什么是'text'?它是'str'吗?你可以向“isWordIn”显示你的电话吗? – CoryKramer 2015-03-02 14:54:55
文字是类似新闻标题的字符串''考拉熊是柔软和可爱'''类TitleTrigger(WordTrigger): def evaluate(self,text): return(self.isWordIn(text))' – Omicron 2015-03-02 15:00:12