假设我正在解析文件,该文件使用;
作为注释字符。我不想解析评论。所以,如果我的线路是这样的:在Python 2.4中,如何在';'之后去掉字符?
example.com. 600 IN MX 8 s1b9.example.net ; hello!
有没有更简单/更优雅的方式来剥离字符了其他比这
rtr = ''
for line in file:
trig = False
for char in line:
if not trig and char != ';':
rtr += char
else:
trig = True
if rtr[max(rtr)] != '\n':
rtr += '\n'
你使用python <2.5吗? – SilentGhost 2009-07-24 18:34:18
是的,python2.4。应该提到的是在?? – lfaraone 2009-07-24 19:42:45
well python2.4是当前稳定版本之后的**两个**版本。你怎么看? – SilentGhost 2009-07-24 19:47:13