For a txt which has the size of files in a dir, I am trying to print the lines where the file appears with less size from a threshold (20Mb) . My code looks like
comp = 200000000
with open("files.txt") as f:
for line in f:
parts = line.split( ) # split line into parts
sz=parts[4]
if ( sz < comp ):
print parts[4], parts[8] # print column 2
The problem is that although I have a record for instance
-rw-rw-r-- 2 user zh 22088417 May 28 19:51 test_file.gz
the code fails to catch it..I suspect is it some failure from python to compare large numbers ? Any ideas ?
thanks
You maybe comparing string to integer. Please convert sz into an integer:
sz = int(parts[4])
Alternatively if you want a float, you would do:
sz = float(parts[4])
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.