import re

from docopt import docopt
import xlrd

__author__ = 'peter'


def main():
    args = docopt(__doc__)
    p = re.compile(args['TERM'], re.UNICODE)
    for f in args['EXCEL_FILE']:
        workbook = xlrd.open_workbook(f)
        sheet = workbook.sheet_by_index(0)
        for rownum in range(sheet.nrows):
            for idx, v in enumerate(sheet.row_values(rownum)):
                if args['-c'] and idx != int(args['-c']):
                    continue
                s = p.search(str(v))
                if s:
                    if args['-o']:
                        print(s.group(0))
                    else:
                        print(sheet.row_values(rownum))


if __name__ == '__main__':
    main()
import re

from docopt import docopt
import xlrd

__author__ = 'peter'


def main():
    args = docopt(__doc__)
    p = re.compile(args['TERM'], re.UNICODE)
    for f in args['EXCEL_FILE']:
        workbook = xlrd.open_workbook(f)
        sheet = workbook.sheet_by_index(0)

        if args['-c']:
            check_row(args, p, sheet, int(args['-c']))
            continue

        for rownum in range(sheet.nrows):
            check_row(args, p, sheet, rownum)


def check_row(args, p, sheet, rownum):
    """
    Check a row for the presence of pattern p.
    """
    for idx, v in enumerate(sheet.row_values(rownum)):
        if args['-c'] and idx != int(args['-c']):
            continue
        s = p.search(str(v))
        if s:
            if args['-o']:
                print(s.group(0))
            else:
                print(sheet.row_values(rownum))


if __name__ == '__main__':
    main()
Add support for single row checking
Add support for single row checking

  import re
  
  from docopt import docopt
  import xlrd
  
  __author__ = 'peter'
  
  
  def main():
      args = docopt(__doc__)
      p = re.compile(args['TERM'], re.UNICODE)
      for f in args['EXCEL_FILE']:
          workbook = xlrd.open_workbook(f)
          sheet = workbook.sheet_by_index(0)
+ 
+         if args['-c']:
+             check_row(args, p, sheet, int(args['-c']))
+             continue
+ 
          for rownum in range(sheet.nrows):
+             check_row(args, p, sheet, rownum)
+ 
+ 
+ def check_row(args, p, sheet, rownum):
+     """
+     Check a row for the presence of pattern p.
+     """
-             for idx, v in enumerate(sheet.row_values(rownum)):
+     for idx, v in enumerate(sheet.row_values(rownum)):
-                 if args['-c'] and idx != int(args['-c']):
+         if args['-c'] and idx != int(args['-c']):
-                     continue
+             continue
-                 s = p.search(str(v))
+         s = p.search(str(v))
-                 if s:
+         if s:
-                     if args['-o']:
+             if args['-o']:
-                         print(s.group(0))
+                 print(s.group(0))
-                     else:
+             else:
-                         print(sheet.row_values(rownum))
+                 print(sheet.row_values(rownum))
  
  
  if __name__ == '__main__':
      main()
Add support for single row checking
## Code Before:
import re

from docopt import docopt
import xlrd

__author__ = 'peter'


def main():
    args = docopt(__doc__)
    p = re.compile(args['TERM'], re.UNICODE)
    for f in args['EXCEL_FILE']:
        workbook = xlrd.open_workbook(f)
        sheet = workbook.sheet_by_index(0)
        for rownum in range(sheet.nrows):
            for idx, v in enumerate(sheet.row_values(rownum)):
                if args['-c'] and idx != int(args['-c']):
                    continue
                s = p.search(str(v))
                if s:
                    if args['-o']:
                        print(s.group(0))
                    else:
                        print(sheet.row_values(rownum))


if __name__ == '__main__':
    main()
## Instruction:
Add support for single row checking
## Code After:
import re

from docopt import docopt
import xlrd

__author__ = 'peter'


def main():
    args = docopt(__doc__)
    p = re.compile(args['TERM'], re.UNICODE)
    for f in args['EXCEL_FILE']:
        workbook = xlrd.open_workbook(f)
        sheet = workbook.sheet_by_index(0)

        if args['-c']:
            check_row(args, p, sheet, int(args['-c']))
            continue

        for rownum in range(sheet.nrows):
            check_row(args, p, sheet, rownum)


def check_row(args, p, sheet, rownum):
    """
    Check a row for the presence of pattern p.
    """
    for idx, v in enumerate(sheet.row_values(rownum)):
        if args['-c'] and idx != int(args['-c']):
            continue
        s = p.search(str(v))
        if s:
            if args['-o']:
                print(s.group(0))
            else:
                print(sheet.row_values(rownum))


if __name__ == '__main__':
    main()