::-- ZoomQuiet [2008-03-21 02:52:28]

CPUG联盟::

CPUG::门户plone

BPUG

SPUG

ZPUG

SpreadPython Python宣传

1. 变量替换技巧

{{{Mr Shore <[email protected]> reply-to [email protected], to "python-cn:CPyUG" <[email protected]>, date Fri, Mar 21, 2008 at 7:13 AM subject [CPyUG:44020] 分享一个变量替换代码 仿tinyp2p }}}

   1 def int2str(i):
   2    return (i<10) and str(i) or (i<36) and chr(i+55) or int2str(i/36) + int2str(i%36)
   3 
   4 strlist = open(r'D:\work\IR\python\compressjs\keyword.txt').read().split('\n')
   5 mplist = []
   6 
   7 for i in range(len(strlist)):
   8    mplist.append('_' + int2str(i))
   9 
  10 print mplist
  11 s = open(r'D:\work\IR\python\compressjs\table.txt','w')
  12 for i,each in enumerate(mplist):
  13    s.write(strlist[i])
  14    s.write('\t\t')
  15    s.write(each)
  16    s.write('\n')

MiscItems/2008-03-21 (last edited 2009-12-25 07:14:55 by localhost)