math.pow表单输入值处理

时间:2013-06-15 03:07:17

标签: python google-app-engine

我问过并且之前被告知有关使用(*变量)解压缩元组来处理exponent函数,该函数在命令行中使用Python时使用逗号分隔的2个值。但现在我要继续使用GAE,当然我需要一个表格。 *解压缩的东西只是提供500个服务器错误。有人还提到分裂...如果我需要使用它,如何/在哪里?这些是用户提交的表单值,而不是静态值。下面的表单有效,但我很难理解如何处理(打印)结果给用户。

form = cgi.FieldStorage(keep_blank_values=1)
raw = form.getvalue('input')

<html>
<body>
<p>Enter base and exponent, separated by a comma.</p>
<form method='post' action="/">
<input type = 'text' name='input'/></p> 
<input type = 'submit' value="Calc"></p>
</form>

根据Dan D的回应更新。问题(500错误)是表单值和映射/拆分功能之间。表单输入类型设置为'text'而map是int ...是问题吗?无论如何它都不起作用。

form = cgi.FieldStorage(keep_blank_values=1)
raw = form.getvalue('input')
processed = map(int, raw.split(","))
readout = pow(*map(int, processed.split(",")))
if raw !="":
    print readout
else: 
    print"" 

1 个答案:

答案 0 :(得分:0)

考虑raw"3,6"的情况:

>>> raw = "3,6"
>>> map(int, raw.split(","))
[3, 6]
>>> pow(*map(int, raw.split(",")))
729