Slexy.org is shutting down and stopped accepting new Pastes on May 4th, 2021.
Existing Pastes will stop being available on or after May 10th, 2021.
Author: Not specified Language: python
Description: Not specified Timestamp: 2017-08-03 22:13:09 +0000
View raw paste Reply
  1. [22:02:38] 1 $ python ./dayid.py
  2. Columns of line: b'thisisevenmorereallylonger    so    itneedstomatch' are not in the right positions
  3.  
  4. [evad@e-vad:~]
  5. [22:04:47] $ python ./dayid.py
  6. Columns of line: 1 are not in the right positions
  7.  
  8. [evad@e-vad:~]
  9. [22:05:57] $ cat dayid_file_2
  10. thisisreallylong              so     whocares
  11. thisisevenmorereallylonger    so    itneedstomatch
  12.  
  13. [evad@e-vad:~]
  14. [22:06:17] $ cat dayid.py
  15. import sys
  16.  
  17. file1 = "/home/evad//dayid_file_1"
  18. file2 = "/home/evad//dayid_file_2"
  19.  
  20. # Taking a swing at https://slexy.org/view/s21C4Dw7kb
  21. # file2 is the broken one, let's check that
  22. f2 = open(file2, "rb")
  23. # Read all the lines
  24. lines = f2.readlines()
  25.  
  26. # Now we store some info about the first line to check the others against
  27. firstLine = lines[0]
  28.  
  29. # wordList is needed to find the positions of things, and to check a thing has
  30. # the right number of columns
  31. wordList = firstLine.split()
  32.  
  33. # Gives us the number of columns
  34. numCols = len(wordList)
  35.  
  36. # Define columnPositions
  37. columnPositions = []
  38.  
  39. # Get the positions of things
  40. for word in wordList:
  41.   position = firstLine.find(word)
  42.   columnPositions.append(position)
  43.  
  44. # Now for the checking of all the things
  45. for lineNum, line in enumerate(lines):
  46.   positions = []
  47.   colsInLine = line.split()
  48.  
  49.   # Check the right number of columns
  50.   if len(colsInLine) != numCols:
  51.     print("Incorrect number of columns on line: %s" % lineNum)
  52.     break
  53.  
  54.   # Check positions
  55.   # First get all the positions of the current line
  56.   for col in colsInLine:
  57.     position = line.find(col)
  58.     positions.append(position)
  59.  
  60.   # Now check if this list matches the other
  61.   if set(positions) != set(columnPositions):
  62.     print("Columns of line: %s are not in the right positions" % lineNum)
  63.     break
  64.  
View raw paste Reply