用Python写ASP

python可以用来写asp,没听说过吧,老实说,我也是今天无意间才知道,于是也自己尝试了一下。下载了ActivePython,装上后,测试了一下代码,顺利通过!

  1. <% @language="python" codepage="936" %>  
  2. <%  
  3. # demo1-输出中文  
  4. class demo:  
  5.   def say(self):  
  6.     return u"你好我的朋友" 
  7. d=demo()  
  8. Response.Write(d.say())  
  9.  
  10. # demo2-使用正则  
  11. Response.Write("<BR>")  
  12. import re  
  13. p=re.compile(",")  
  14. a=p.split("a,b,c")  
  15. for x in a:  
  16.   Response.Write("value:" + x + "<BR>")  
  17.  
  18. p2=re.compile("item\d+")  
  19. a2=p2.findall("1 list item1 2 list item2 3 list item3")  
  20. for x in a2:  
  21.   Response.Write("value:" + x + "<BR>")  
  22. %> 

特别需要注意的是编码,否则不能输出中文,这里我写了这两个简易的例子,一个是类实例的输出,一个是正则的使用,更详细的使用还在探索中...

posted @ 2009-05-07 14:59  shaoyun  阅读(372)  评论(0编辑  收藏  举报