旧文-初学python-2007-10-07 21:19

 

从昨天晚上开始,学习了一下python。看的这本翻译的教程,写得很好,浅显易懂,推荐给入门用户。
wiki上的链接也很有用。
另外,当作练手写了一个去除51汇编程序的注释的小程序。非常简单。

 

#!/usr/bin/python
# Filename : anticom.py
""" delete the comment of a given assembly file"""

import sys

if len(sys.argv) < 2:
    print 'No file name specified.'
    sys.exit()

filename = sys.argv[1]
f = file(filename)
f_out = file( 'new' + filename,'w')

while True:
    line = f.readline()
    if len(line) == 0:
        break

    a=line.find(';') #if this line has no ';', a=-1, it's just OK
    newline=line[:a] + '; '
    f_out.write(newline)

f.close
f_out.close

  

posted on 2017-06-28 19:59  fishhead  阅读(162)  评论(0编辑  收藏  举报

导航