下边是用Python编写的一个ASP页面:
<%@LANGUAGE="python" CODEPAGE="936"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>Python测试-Mzwu.Com</title>
</head>
<body>
<%
from Rectangle import *
rectangle = Rectangle(50,100)
area = rectangle.Area()
Response.Write(area)
Response.Write("<br/>")
Response.Write(rectangle.ToString())
Response.Write("<br/>")
Response.Write(str(rectangle.__dict__))
%>
</body>
</html>Rectangle.py:
#Python 2.6.2
class Rectangle:
'''Class Rectangle.
description.'''
#constructor
def __init__(self,width,height):
self.Width = width
self.Height = height
#public methods
def Area(self):
return self.Width * self.Height
def ToString(self):
return 'Width:%s,Height:%s' % (self.Width,self.Height)说明:Rectangle.py必须放在sys.path其中一个路径中,否则程序运行会出错,提示:ImportError: No module named Rectangle!
评论(0)
暂无评论。