Пример #1
0
 def print_data(self):
     print('')
     # start with empty queue, must set self.isover.value
     while not self.isover.value or not self.queue.empty():
         try:
             data = self.queue.get_nowait()
             # 调用基类的方法
             data = BaseDB.format_data(self, data)
             if self.args.format == JSON_FORMAT or self.args.metaj:
                 row = data
             else:
                 items = []
                 for item in data:
                     if item is None:
                         items.append('None')
                     elif isinstance(item, (int, float)):
                         items.append(str(item))
                     else:
                         items.append(safe_decode(item))
                 row = self.args.outspliter.join(items)
             print(row)
             if self.args.interval:
                 time.sleep(self.args.interval)
         except queue.Empty:
             pass
         except Exception as e:
             print(e)
Пример #2
0
def read_file_lines(filepath):
    if not os.path.exists(filepath):
        raise FileNotFoundError(filepath)
    with compat_open(filepath, 'r', encoding='utf8') as fp:
        lines = fp.read()
        lines = lines.splitlines()
        # start with # is comment line, and filter empty line
        lines = [safe_decode(line) for line in lines if line and not line.strip().startswith("#") and line.strip()]
    return lines
Пример #3
0
def read_file_lines(filepath):
    contents = read_file(filepath)
    lines = contents.splitlines()
    # start with # is comment line, and filter empty line
    lines = [safe_decode(line) for line in lines if line and not line.strip().startswith("#") and line.strip()]
    return lines