gpt4 book ai didi

python - Python中的TypeError 'classobj'对象没有属性 '__getitem__'

转载 作者:行者123 更新时间:2023-11-30 23:21:11 25 4
gpt4 key购买 nike

我只是 python 的初学者,我不知道如何解决这个问题。请帮忙。

错误:

Traceback (most recent call last):
File "C:\Users\Priscilla\Desktop\CMPT Assn #3\page.py", line 17, in <module>
print "<p>Customer Name:", form["custName"].value, "</p>"
TypeError: 'classobj' object has no attribute '__getitem__'

Python 脚本:

import cgi
form = cgi.FieldStorage

# print HTTP/HTML header stuff
print """Content-type: text/html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html><head>
<title>Order Form</title>
</head><body>
"""

# print HTML body using form data
print "<h1>Kintoro Japanese Bar &amp; Restaurant</h1>"
print "<h2>Customer Reciept</h2>"
print "<p>Customer Name:", form["custName"].value, "</p>"
print "<p>Customer Email Address:", form["custEmail"].value, "</p>"
print "<h2>Customer Address:</h2>"
print "<p>Street:", form["custAdd"].value, "</p>"
print "<p>City:", form["custCity"].value, "</p>"
print "<p>Province:", form["custProv"].value, "</p>"
print "<p>Postal Code:", form["custPostal"].value, "</p>"
print "<h2>Payment Information:</h2>"
print "<p>Card Type:", form["type1"].value, "</p>"
print "<p>Card Number: XXXX-XXXX-XXXX-", form["four4"].value, "</p>"
print "<p>Expiry Date:", form["expDate"].value, "</p>"

最佳答案

form = cgi.FieldStorage 将类 FieldStorage 本身分配给 form。您想改为分配 FieldStorage 的实例:

form = cgi.FieldStorage()

关于python - Python中的TypeError 'classobj'对象没有属性 '__getitem__',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25071076/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com