Python "classobj"错误

标签 python

我有这段代码,但我无法运行它,因为我得到了这个错误: “TypeError:'classobj' 对象不可订阅” 这是我的代码:

import cgi
import customerlib

form=cgi.FieldStorage

history = customerlib.find(form["f_name"].value,form["l_name"].value)


print "Content-type: text/html"
print
print """<html>
  <head>
    <title>Purchase history</title>
  </head>
  <body>
    <h1>Purchase History</h1>"""

print "<p>you have a purchase history of:"
for i in history: "</p>"
   print"""  <body>
</html>"""

我在这个文件旁边有 customerlib 文件。知道如何解决吗?

最佳答案

form=cgi.FieldStorage

FieldStorage是一个类,不是一个对象。您需要实例化它以创建 FieldStorage对象:

form=cgi.FieldStorage()

它在 form["f_name"] 上出错因为 form 当前是 FieldStorage 类的别名, 不是 FieldStorage 类型的对象.通过实例化它,它正在做您认为应该做的事情。

查看 cgi module documentation有关如何使用 CGI 模块的更多详细信息。

关于Python "classobj"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10020350/

相关文章:

python - 优雅地捕获 SIGSTOP 和 SIGKILL

python - 如何在python中匹配人脸

python - 使用 Python 解码 JSON 并存储嵌套对象

python - 回溯(最近一次调用): File "<stdin>", 第 1 行,在 <module> 中 TypeError: object() 不带任何参数

python - 将诺伊曼边界条件应用于扩散方程

python - 根据列组合在数据框中创建唯一标识符

python - Django 内部 API 客户端/服务器身份验证与否?

python - 连接器/python executemany NoneType

python - 在 python 中解析字符串

python - 如何让 django 表单向导 extra_context 显示在模板上?