嗨,我想從html表單獲取輸入並將其傳遞給我的python腳本並使其執行,然後我想在瀏覽器中打印我的結果而不使用任何框架。下面是我的Python代碼:Python: - 將HTML表單輸入傳遞給python代碼並執行它
import re
hap=['amused','beaming','blissful','blithe','cheerful','cheery','delighted']
sad=['upset','out','sorry','not in mood','down']
sad_count=0
happy_count=0
str1=raw_input("Enter Message...\n")
happy_count=len(filter(lambda x:x in str1,hap))
sad_count=len(filter(lambda x:x in str1,sad))
if(happy_count>sad_count):
print("Hey buddy...your mood is HAPPY :-)")
elif(sad_count>happy_count):
print("Ouch! Your Mood is Sad :-(")
elif(happy_count==sad_count):
if(happy_count>0 and sad_count>0):
print("oops! You are in CONFUSED mood :o")
else:
print("Sorry,No mood found :>")
您需要某種網絡服務器,運行html模板,並創建一個處理代碼的回調函數。看看一些基本的cgi/wsgi [示例](http://wiki.python.org/moin/CgiScripts) – dorvak