[Python] python信息替换演示代码 →→→→→进入此内容的聊天室

来自 , 2019-07-26, 写在 Python, 查看 100 次.
URL http://www.code666.cn/view/a71378c0
  1. Escape = "^"  
  2.  
  3. def subst(Msg, *Args) :  
  4.     """substitutes Args into Msg."""  
  5.     Result = ""  
  6.     while True :  
  7.         Items = Msg.split(Escape, 1)  
  8.         Result += Items[0]  
  9.         if len(Items) == 1 or len(Items[1]) == 0 :  
  10.             break  
  11.         Msg = Items[1]  
  12.         (Ch, Msg) = (Msg[:1], Msg[1:])  
  13.         if Ch == Escape :  
  14.             Result += Escape  
  15.         elif Ch >= "0" and Ch <= "9" :  
  16.             Result += Args[ord(Ch) - ord("0")]  
  17.         #end if  
  18.     #end while  
  19.     return Result  
  20. #end subst  
  21.  
  22.  
  23. #//python/4608

回复 "python信息替换演示代码"

这儿你可以回复上面这条便签

captcha