2012-04-04 48 views
1

我有这样的代码,我不能跑,因为我得到这个错误: “类型错误:‘classobj’对象未标化” 这里是我的代码:的Python“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文件。任何想法如何解决它?

回答

6
form=cgi.FieldStorage 

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

form=cgi.FieldStorage() 

它是form["f_name"]示数,因为形式是当前类的FieldStorage,不FieldStorage类型的对象的别名。通过实例化它,它正在做你认为应该做的事情。

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