class Parser():
html_escape_table = {
"&": "&",
'"': """,
"'": "'",
">": ">",
"<": "<",
}
def html_escape(text):
return "".join(html_escape_table.get(c,c) for c in text)
def query():
database = [x, y, z, etc, etc2]
for x in database:
html_escape(x)
print x #for testing purposes
return
test = Parser()
test.query()
上午我做正确吗?我不断收到一个错误:第一次使用类 - 我做错了什么?
TypeError: query() takes no arguments (1 given)
我没有看到任何地方,我传递参数查询,甚至解析器。
有人能解释什么,我做错了什么?
我打过电话只是Parser.query(),并得到这个错误(这是将自我论证我所有的功能和对象的参数传递给我的分析器类后),类
Parser.query()
TypeError: unbound method query() must be called with Parser instance as first argument (got nothing instead)
一个类总是传递一个对自身的引用作为第一个参数。改变'query()'的定义为'def query(self):' –
你应该阅读Python教程,它解释了所有这些。 – BrenBarn
等待,如果'query'没有在Parser对象中使用任何东西,那么为什么你把它写成'Parser'的方法呢?为什么不把它作为函数保存在类之外的同一个文件中? – inspectorG4dget