2012-04-04 49 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模塊的更多詳細信息。