1 Star 0 Fork 46

chundonglinlin/qytang_Python

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
2016.02.13 cgi language 打印小实验 PY 1.23 KB
一键复制 编辑 原始数据 按行查看 历史
现任明教教主-乾颐堂 提交于 2016-02-13 10:52 . new file
#!/usr/bin/python3.4
debugme = False
inputkey = 'language'
hellos = {
'Python': r" print('Hello World') ",
'Python2': r" print 'Hello World' ",
'Perl': r" print 'Hello World\n'; ",
'Tcl': r" puts 'Hello World' ",
'Java': r" System.out.println ('Hello World'); ",
'C': r" printf ('Hello World\n'); ",
'C++': r" cout << 'Hello World' << endl; "
}
class dummy:
def __init__(self, str): self.value = str
import cgi, sys
if debugme:
# print(debugme)
form = {inputkey: dummy(sys.argv[1])}
else:
form = cgi.FieldStorage()
print("Content-type: text/html\n")
print("<TITLE>Languages</TITLE>")
print("<H1>Syntax</H1><HR>")
def showHello(form):
choice = form[inputkey].value
print("<H3>%s</H3><P><PRE>" % choice)
try:
# print(form)
print(cgi.escape(hellos[choice]))
except KeyError:
print("Sorry -- I don'not Know that language")
print("</PRE></P><BR>")
if not inputkey in form or form[inputkey].value == 'ALL':
for lang in hellos.keys():
mock = {inputkey: dummy(lang)}
showHello(mock)
else:
showHello(form)
print("<HR>")
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/chundonglinlin/qytang_Python.git
git@gitee.com:chundonglinlin/qytang_Python.git
chundonglinlin
qytang_Python
qytang_Python
master

搜索帮助