OSDN Git Service

add a scriptlet to delete the first line when it is blank.
[sawarabi-fonts/sawarabi-fonts.git] / script / listprinter.py
1 # -*- coding: utf-8 -*-
2
3 # Author: mshio <mshio@users.sourceforge.jp>
4
5 __version__ = '0.11'
6
7 import sys
8
9 class SimpleListPrinter:
10     def __init__(self, col=10, out=sys.stdout, delimiter=' '):
11         self.col = col
12         self.out = out
13         self.delimiter = self._get_delimiter(delimiter)
14
15     def output(self, array):
16         n = 0
17         size = len(array)
18         for c in array:
19             n += 1
20             self.out.write(unichr(c).encode('utf-8'))
21             delimiter = self.delimiter if n % self.col != 0 and n < size else '\n'
22             self.out.write(delimiter)
23
24     def _get_delimiter(self, delimiter):
25         ch = None
26         if type(delimiter) == int:
27             ch = unichr(delimiter).encode('utf-8')
28         elif type(delimiter) == unicode:
29             ch = delimiter.encode('utf-8')
30         elif type(delimiter) == str:
31             ch = delimiter
32         return ch