用python 找到不存在的数字

先用bash脚本排序,然后用python脚本找出丢失的数字。当然,也可以完全在python脚本中完成。

# !/usr/bin/python
#
filename:findlost.py
#
author:zhouhh
#
http://blog.csdn.net/ablo_zhou
#
email:[email protected]
#
date:2008.3.31
#
Findoutwhatnumberislostfromafile

import os

infilename
= raw_input( " infilename[rawpack]: " );
outfilename
= raw_input( " outfilename[outfile]: " );

if infilename == "" :
infilename
= " rawpack " ;

if outfilename == "" :
outfilename
= " outfile " ;

cmd
= ( " sort.sh " ,infilename,outfilename)
os.system(
' ' .join(cmd))

f
= open(outfilename);

i
= 0
pkid
= 0
count
= 0
while True:
line
= f.readline()
if len(line) == 0:
f.close()
break

pkid
= int(line)
if pkid > i:
print " lostpackage " ,i
i
+= 1
count
+= 1
i
+= 1
print " ================================= "
print " totalpackagenumis " ,pkid, " ,lostpackagecount: " ,count


执行结果:

$ ./ findlost . py
infilename[rawpack]:
outfilename[outfile]:
./ sort . sh , rawpack , outfile
lostpackage
1707
lostpackage
2126
lostpackage
2139
lostpackage
2278
lostpackage
2280
lostpackage
2475
lostpackage
2763
lostpackage
3014
lostpackage
3072
lostpackage
3165
lostpackage
3271
=================================
totalpackagenumis
3778 , lostpackagecount: 11

你可能感兴趣的:(python,OS,脚本,bash,Gmail)