我正在寻找一种方法来组合我的PHP代码到我的Python文件。也许很奇怪,但对我来说很有帮助。我只是想用Python编写这部分php代码,因为我不知道如何用Python重写它:(
function counter_winkelkar()
{
global $order;
global $refname;
if(isset( $_POST['clearknop'] ))
{
$_SESSION['count']= '0';
unset($_SESSION['array_products']);
unset($_SESSION['array_counting_products']);
}
if (isset( $_POST['refname'] ))
{
$_SESSION['count']= $_SESSION['count'] + $order;
print("$_SESSION[count]");
}
}
function products_winkelkar()
{
global $order;
global $db;
global $refname;
if (!isset($_SESSION['array_products']) )
{
$_SESSION['array_products'] = Array();
$_SESSION['array_counting_products'] = Array();
}
if ($order != 'number' )
{
array_push($_SESSION['array_products'],$refname);
array_push($_SESSION['array_counting_products'],$order);
}
}
function winkelkar()
{
counter_winkelkar();
products_winkelkar();
}
winkelkar();
?>
这是我使用web.py编写的一个Python web应用程序,它近似于一个可以被清除的计数器。也许它可以帮助你移植你的PHP:
import web
_SESSION = {}
urls = (
'/', 'index'
)
app = web.application(urls, globals())
class index:
def POST(self):
if 'clearknop' in web.input():
_SESSION['count'] = 0
else:
if 'count' not in _SESSION:
_SESSION['count'] = 0
_SESSION['count'] = _SESSION['count'] + 1
return _SESSION['count']
def GET(self):
return """<form method='POST' action='/'>
<input type='checkbox' name='clearknop'/> Clear
<input type='submit'/>
</form>"""
if __name__ == "__main__":
app.run()
你的PHP示例缺少很多内容来涵盖你的问题中的每个特性。例如,$order
是如何填充的,$refname
包含什么样的值?